Advertisement
Guest User

Untitled

a guest
Sep 28th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Tab Scroll JS
  2.  
  3. function tabScroll(event) {
  4.     const target = event.target;
  5.     if (target.classList.contains('title')) {
  6.         const par = target.parentNode;
  7.         if (par.classList.contains('tab-header') && target.hasAttribute('id')) {
  8.             const id = target.getAttribute('id');
  9.             if (id === 'scrollTop') {
  10.                 chrome.tabs.executeScript({code:'function pos(){var position=window.pageYOffset;window.scrollTo(0,0);return position;};pos();'}, msg);
  11.                 target.id = 'scrollPre';
  12.             }
  13.             if (id === 'scrollPre') {
  14.                 chrome.tabs.executeScript({code:'chrome.storage.local.get({"offset":""},function(local){var offset=local.offset;window.scrollTo(0,offset);});'});
  15.                 target.id = 'scrollTop';
  16.             }
  17.         }
  18.         if (par.classList.contains('tab-header') && !target.hasAttribute('id')) {
  19.             rmID();
  20.             target.id = 'scrollTop';
  21.         }
  22.     }
  23. };
  24.  
  25. function msg(position) {
  26.     var offset = position[0];
  27.     chrome.storage.local.set({'offset': offset});
  28. };
  29.  
  30. function rmID() {
  31.     const top = document.getElementById('scrollTop');
  32.     const pre = document.getElementById('scrollPre');
  33.     if (top) {
  34.         top.removeAttribute('id');
  35.     }
  36.     if (pre) {
  37.         pre.removeAttribute('id');
  38.     }
  39. };
  40.  
  41.  
  42. // Toggle JS
  43.  
  44. function extensionToggle() {
  45.  
  46. // Add extension IDs of buttons. On each click of the toggle another set of buttons is being shown. You can leave any one of these empty. In this example no extensions are being shown on start, 3 extensions are being shown in set2 and 3 in set3. Extension that are installed and enabled but not entered will be hidden from all sets.
  47.  
  48. // Hidden extensions (Keep it blank)
  49.     var set1 =
  50.         [
  51.         ];
  52. // Always shown ?
  53.     var set2 =
  54.         [
  55.         'hkhcjamebchhnoddfipklniglomopkcm', //ScriptJager
  56.         'emdjionoeijnepnlidmpilichaijlmoe', //FlashVideoDownloaderUnpacked
  57.         'gabbbocakeomblphkmmnoamkioajlkfo', //NanoAdBlocker
  58.         'imkngaibigegepnlckfcbecjoilcjbhf', //StreamVideoDownload
  59.         'fhcgjolkccmbidfldomjliifgaodjagh' //CookieAutodelete
  60.         ];
  61. // Show on toggle
  62.     var set3 =
  63.         [
  64.         'fbbmnbomimdgmecfpbilhoafgmmeagef', //PageZipper
  65.         'hmdcmlfkchdmnmnmheododdhjedfccka', //EyeDropper
  66.         'ekajjllcmeckibblgckgoceinmmgnfop', //FloatingPlayer
  67.         'ljnpgplmnnnbebdgjnbejbcamhdflibm', //ForceBackgroundTabs
  68.         'lmeddoobegbaiopohmpmmobpnpjifpii', //OpenInFirefox
  69.         'dmpojjilddefgnhiicjcmhbkjgbbclob' //YoutubeDownloader
  70.         ];
  71.  
  72.     // create the button
  73.     var button = document.createElement('button');
  74.     button.classList.add('button-toolbar', 'toggle-extensions-group');
  75.     button.id = 'togglemod';
  76.     button.setAttribute('title', 'Toggle mod');
  77.     button.setAttribute('tabindex', '-1');
  78.     button.innerHTML = '<svg width="4" height="16" viewBox="0 0 4 16" xmlns="http://www.w3.org/2000/svg"><path d="M2 4c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zm0 6c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zm0 6c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z"></path></svg>';
  79.     adr.appendChild(button);
  80.  
  81.     // startup setting
  82.     const startup = document.querySelectorAll('button.button-toolbar.browserAction-button');
  83.     const togstat = document.getElementById('togglemod');
  84.     togstat.classList.add('SET1');
  85.     for (var i=0; i < startup.length; i++) {
  86.         if (set1.indexOf(startup[i].id) != -1) {
  87.             startup[i].style.display = 'flex';
  88.         }
  89.         else {
  90.             startup[i].style.display = 'none';
  91.         }
  92.     }
  93.  
  94.     // toggle logic
  95.     togstat.addEventListener('click', function() {
  96.         const buttons = document.querySelectorAll('button.button-toolbar.browserAction-button');
  97.         if (togstat.classList.contains('SET1')) {
  98.             togstat.classList.remove('SET1');
  99.             togstat.classList.add('SET2');
  100.         }
  101.         else if (togstat.classList.contains('SET2')) {
  102.             togstat.classList.remove('SET2');
  103.             togstat.classList.add('SET3');
  104.         }
  105.         else {
  106.             togstat.classList.remove('SET3');
  107.             togstat.classList.add('SET1');
  108.         }
  109.         for (var i=0; i < buttons.length; i++) {
  110.             if (togstat.classList.contains('SET1') && set1.indexOf(buttons[i].id) != -1) {
  111.                 buttons[i].style.display = 'flex';
  112.             }
  113.             else if (togstat.classList.contains('SET2') && set2.indexOf(buttons[i].id) != -1) {
  114.                 buttons[i].style.display = 'flex';
  115.             }
  116.             else if (togstat.classList.contains('SET3') && set3.indexOf(buttons[i].id) != -1) {
  117.                 buttons[i].style.display = 'flex';
  118.             }
  119.             else {
  120.                 buttons[i].style.display = 'none';
  121.             }
  122.         }
  123.     });
  124. };
  125.  
  126.  
  127. // Below code is a loop waiting for the browser to load the UI. Something like it has to be used in all similar javascript mods to ensure the interface has loaded before running dependent functions. You can call all functions you might use from just one instance.
  128.  
  129. let adr = {};
  130. setTimeout(function wait() {
  131.     adr = document.querySelector('.toolbar-addressbar.toolbar');
  132.     if (adr) {
  133.         extensionToggle();
  134.         document.body.addEventListener('click', tabScroll);
  135.     }
  136.     else {
  137.         setTimeout(wait, 300);
  138.     }
  139. }, 300);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement