Skip to content

Commit

Permalink
add counterapi
Browse files Browse the repository at this point in the history
  • Loading branch information
domescala committed Feb 21, 2024
1 parent 24ce277 commit 2418a9d
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 8 deletions.
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ <h1>aule libere polito</h1>
</span>
<p>
Per qualsiasi problema fai uno screenshot e invialo a <a
target="_blank"
href="https://t.me/domescala">@domescala</a> su
telegram. Daje
</p>
Expand Down Expand Up @@ -338,14 +339,14 @@ <h1>-</h1>
</div>
</div>


<script src="https://counterapi.com/counterapi.embed.js" ></script>
<script src="result.js"></script>
<script src="js/dome_vanillajs.js"></script>
<script src="js/classrooms_info.js"></script>
<script src="js/classrooms_data.js"></script>
<script src="js/parse_classrooms_data.js"></script>
<script src="js/counter.js"></script>
<script src="js/main.js"></script>
<script src="js/counterviews.js"></script>

</body>

Expand Down
73 changes: 73 additions & 0 deletions js/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const COUNTER = {
favorite_add: function(classroom){
counter_increment("favorite classrooms", "Aula " + classroom)
},
classroom_opening: function (classroom) {
counter_increment("watch classrooms", "Aula " + classroom)
},
campus_selected: function (campus) {
counter_increment("campus selected", campus)
},
filter_selected: function (filter) {
counter_increment("filter selected", filter)
},
click_buttons: function (button) {
counter_increment("click_buttons", button)
},
click_links: function (link) {
counter_increment("click_links", link)
},
main_page: function () {
counter_increment("view", "mainpage")
}
}


var counter_increment = function(){}



window.addEventListener("load", function () {
setTimeout(() => {
COUNTER.main_page()
counter_increment = function (action, key){
var namespace = 'auleliberev2'
var options = { behavior: 'vote' }

counterApi.increment(key, action, namespace, options, function(err, res){
console.log(res)
})

}
}, 10);
})

q("#search_main").addEventListener("mousedown", function () {

COUNTER.click_buttons("main search")
})
q("#search_main").addEventListener("input", function () {

COUNTER.click_buttons("run search")
})
q("#button_search_class").addEventListener("mousedown", function () {

COUNTER.click_buttons("bottom search")
})

Q(".date_input").forEach(e => {
e.addEventListener("click", function () {
COUNTER.click_buttons("open date")
})
})

q("#campus_input").addEventListener("click", function () {
COUNTER.click_buttons("open campus")
})


Q("a").forEach(e => {
e.addEventListener("mousedown", function () {
COUNTER.click_links(e.innerHTML)
})
});
5 changes: 0 additions & 5 deletions js/counterviews.js

This file was deleted.

14 changes: 13 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ function updateDoc_campus(campus, disp){
});
updateDoc_date(disp)
setup_search_modal()

COUNTER.campus_selected(Selected_campus)
}

function remove_columns(n_fasceorarie) {
Expand Down Expand Up @@ -452,6 +454,7 @@ function load_localStorage(){
else{
localStorage["favorites"] = "[]"
}

}


Expand Down Expand Up @@ -540,6 +543,8 @@ function open_modal(id_row){
else{
q("#modal_favorite").removeClass("favorite")
}

COUNTER.classroom_opening(Aula_modal)
}

function exit_modal(){
Expand Down Expand Up @@ -576,6 +581,7 @@ FILTERS.forEach(filter => {
filtra_aule("reset")
}

COUNTER.filter_selected(filter.getAttribute("value").replace("_", ""))
})
});

Expand All @@ -591,6 +597,8 @@ Q(".row_aule").forEach(ROW => {
})
})

// ---- FAVORITE ADD BUTTON ----

q("#modal_favorite").addEventListener("click", function(){
q("#modal_favorite").toggleClass("favorite")
q('[_id="' + Aula_modal + '"]').toggleClass("favorite")
Expand All @@ -604,6 +612,8 @@ q("#modal_favorite").addEventListener("click", function(){
}
localStorage["favorites"] = JSON.stringify(Favorites)
Order_favorites()

COUNTER.favorite_add(Aula_modal)
})
function Order_favorites(){
// i valori di order dipendono se il Filtro è attivo o no e se è nei preferiti o no
Expand Down Expand Up @@ -710,6 +720,7 @@ function change_date(this_element){

updateDoc_date(disp)
}
COUNTER.click_buttons("change date")
}

function change_campus(this_element) {
Expand Down Expand Up @@ -814,12 +825,13 @@ q("#button_search_class").addEventListener("click", function(){
// open_modal_search()
q("#search_main").focus()
q("#button_search_class").removeClass("button_search_appear")

})

q("#search_main").addEventListener("input", function(){
let val = q("#search_main").value.toUpperCase()
q("#search_main").value = val;

// se contiene il carattere nascosto al fondo allora è stato premuto sulla datalist
if (val.slice(-1) === '\u2063') {
val = val.slice(0, -1); //rimuovi il carattere e lancia il modal
Expand Down

0 comments on commit 2418a9d

Please sign in to comment.