ingokodba

moodle merlin keyboard shortcuts

Apr 7th, 2021 (edited)
384
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Made to navigate links faster (with keyboard) on merlin site of any collegium
  3. HOW TO: To integrate script, install some extension that enables custom javascript such as Custom Style Script (https://chrome.google.com/webstore/detail/custom-style-script/ecjfaoeopefafjpdgnfcjnhinpbldjij).
  4. Navigation: Use key J to move section backwards and key L to move section forward. Press number or letter corresponding to link inside section to go to that link
  5. */
  6.  
  7. var oznaceno = undefined;
  8. var oznaceno_indeks = 0;
  9. var xic = undefined;
  10. var apendanstil = false;
  11.  
  12. window.onload = (event) => {
  13.     appendastyle();
  14.     nadiPrvu();
  15.     nadi();
  16.  
  17.     document.body.onkeyup = function(e){
  18.         if(e.keyCode >= 49 && e.keyCode <= 57){
  19.             oznaceno.querySelectorAll("ul")[0].querySelectorAll("li")[e.keyCode-49].querySelectorAll("a")[0].click();
  20.         }
  21.         if(e.keyCode >= 65 && e.keyCode <= 73){
  22.             oznaceno.querySelectorAll("ul")[0].querySelectorAll("li")[e.keyCode-65+9].querySelectorAll("a")[0].click();
  23.         }
  24.         if(e.keyCode >= 77 && e.keyCode <= 90){
  25.             oznaceno.querySelectorAll("ul")[0].querySelectorAll("li")[e.keyCode-65+9-3].querySelectorAll("a")[0].click();
  26.         }
  27.         if(e.keyCode == 74){
  28.             oznaceno_indeks--;
  29.             nadi();
  30.         }
  31.         if(e.keyCode == 76){
  32.             oznaceno_indeks++;
  33.             nadi();
  34.         }
  35.         if(e.keyCode == 75){
  36.             nadiPrvu();
  37.             nadi();
  38.         }
  39.     }
  40. };
  41.  
  42. function nadi(){
  43.     if(oznaceno != undefined) oznaceno.style.backgroundColor = "#fff";
  44.     oznaceno = xic.querySelectorAll("#section-"+oznaceno_indeks)[0];
  45.     if(oznaceno != undefined){
  46.         oznaceno.style.backgroundColor = "#ccc";
  47.         oznaceno.scrollIntoView(false);
  48.         dodajKeyHintove();
  49.     }
  50.     console.log(oznaceno_indeks);
  51. }
  52.  
  53. function nadiPrvu(){
  54.     //regijamain = document.getElementById("region-main");
  55.     xic = document.getElementById("region-main").querySelectorAll("ul")[0];
  56.     if(apendanstil == false) appendastyle();
  57. }
  58.  
  59. function appendastyle(){
  60.     var style = document.createElement('style');
  61.   style.innerHTML = `
  62.   .pomoc {
  63.     background: #fff;
  64.     padding: 1px 5px;
  65.     position: absolute;
  66.   }
  67.   `;
  68.   document.head.appendChild(style);
  69.   apendanstil = true;
  70. }
  71.  
  72. function dodajKeyHintove(){
  73.     var paras = document.getElementsByClassName('pomoc');
  74.  
  75.     while(paras[0]){
  76.         paras[0].parentNode.removeChild(paras[0]);
  77.     }
  78.  
  79.  
  80.     var k = oznaceno.querySelectorAll("ul")[0].querySelectorAll("li");
  81.    
  82.  
  83.     for (var i = 0; i < k.length; i++) {
  84.       addKeyHint(k[i], i+1);
  85.     }
  86. }
  87.  
  88. function addKeyHint(element_of_key, num){
  89.     y = element_of_key.offsetTop;
  90.     x = element_of_key.offsetLeft;
  91.     console.log(x + " " + y);
  92.     var divic = document.createElement("div");
  93.     if(num < 10){
  94.         divic.innerHTML = num;
  95.     } else {
  96.         if(num >= 19){
  97.             divic.innerHTML = String.fromCharCode(97+num+3-10);
  98.         } else {
  99.  
  100.             divic.innerHTML = String.fromCharCode(97+num-10);
  101.         }
  102.     }
  103.     divic.classList.add("pomoc");
  104.     divic.style.top = (y+2) + "px";
  105.     divic.style.left = (x+9) + "px";
  106.     oznaceno.appendChild(divic);   
  107. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×