default.js - dotfiles - leot's dotfiles
 (HTM) hg clone https://bitbucket.org/iamleot/dotfiles
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       default.js
       ---
            1 /*
            2  * Fix "lazy" loaded image.
            3  */
            4 (function() {
            5 
            6         document.querySelectorAll("img[data-thumb]").forEach(function(e) {
            7                 e.src = e.getAttribute("data-thumb");
            8         });
            9 
           10         document.querySelectorAll("img[data-src]").forEach(function(e) {
           11                 e.src = e.getAttribute("data-src");
           12         });
           13 
           14         document.querySelectorAll("img[data-original]").forEach(function(e) {
           15                 e.src = e.getAttribute("data-original");
           16         });
           17 
           18 })();
           19 
           20 
           21 /*
           22  * Never open link in new tabs.
           23  */
           24 (function() {
           25 
           26         document.querySelectorAll("a[target=_blank]").forEach(function(e) {
           27                 e.removeAttribute("target");
           28         });
           29 
           30 })();
           31 
           32 
           33 /*
           34  * Add `p' and `n' accesskey-s (previous/next via `Mod1 + p'/`Mod1 + n')
           35  */
           36 (function() {
           37 
           38         previous_selectors = [
           39                 'a[rel="prev"]',
           40                 'a[aria-label="Pagina precedente"]',    // google.it
           41                 'a[aria-label="Previous page"]',        // google.com
           42         ];
           43         previous_res = [
           44                 /<</,
           45                 /«/,
           46                 /←/,
           47                 /◀/,
           48                 /❬/,
           49         ];
           50 
           51         next_selectors = [
           52                 'a[rel="next"]',
           53                 'a[aria-label="Pagina successiva"]',    // google.it
           54                 'a[aria-label="Next page"]',            // google.com
           55         ];
           56         next_res = [
           57                 />>/,
           58                 /»/,
           59                 /→/,
           60                 /▶/,
           61                 /❭/,
           62         ];
           63 
           64         has_prev = false;
           65         has_next = false;
           66 
           67         if (document.querySelector('*[accesskey="p"]')) {
           68                 has_prev = true;
           69         }
           70         if (document.querySelector('*[accesskey="n"]')) {
           71                 has_next = true;
           72         }
           73 
           74         if (!has_prev) {
           75                 for (p of previous_selectors) {
           76                         if (e = document.querySelector(p)) {
           77                                 e.accessKey = "p";
           78                                 has_prev = true;
           79                                 break;
           80                         }
           81                 }
           82         }
           83         if (!has_next) {
           84                 for (n of next_selectors) {
           85                         if (e = document.querySelector(n)) {
           86                                 e.accessKey = "n";
           87                                 has_next = true;
           88                                 break;
           89                         }
           90                 }
           91         }
           92 
           93         for (i = document.links.length - 1; !has_prev && i >= 0; i--) {
           94                 for (p of previous_res) {
           95                         if (document.links[i].text &&
           96                             document.links[i].text.match(p)) {
           97                                 document.links[i].accessKey = "p";
           98                                 has_prev = true;
           99                                 break;
          100                         }
          101                 }
          102         }
          103         for (i = document.links.length - 1; !has_next && i >= 0; i--) {
          104                 for (n of next_res) {
          105                         if (document.links[i].text &&
          106                             document.links[i].text.match(n)) {
          107                                 document.links[i].accessKey = "n";
          108                                 has_next = true;
          109                                 break;
          110                         }
          111                 }
          112         }
          113 
          114 })();