difool2nice

userchrome.js

Apr 2nd, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           userChrome.js
  3. // @namespace      scrollbars_win10
  4. // @version        0.0.4
  5. // @note           Windows 10 style by /u/mrkwatz https://www.reddit.com/r/FirefoxCSS/comments/7fkha6/firefox_57_windows_10_uwp_style_overlay_scrollbars/
  6. // @note           Brought to Firefox 57 by /u/Wiidesire https://www.reddit.com/r/firefox/comments/7f6kc4/floating_scrollbar_finally_possible_in_firefox_57/
  7. // @note           userChrome.js https://github.com/nuchi/firefox-quantum-userchromejs
  8. // @note           Forked from https://github.com/Endor8/userChrome.js/blob/master/floatingscrollbar/FloatingScrollbar.uc.js
  9. // ==/UserScript==
  10.  
  11. (function () {
  12.     var prefs = Services.prefs,
  13.         enabled;
  14.     if (prefs.prefHasUserValue('userChromeJS.floating_scrollbar.enabled')) {
  15.         enabled = prefs.getBoolPref('userChromeJS.floating_scrollbar.enabled')
  16.     } else {
  17.         prefs.setBoolPref('userChromeJS.floating_scrollbar.enabled', true);
  18.         enabled = true;
  19.     }
  20.  
  21.     var css = `
  22.         @namespace url(http: //www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);
  23.         :not(select):not(hbox) > scrollbar {
  24.             -moz-appearance: none!important;
  25.             position: relative!important;
  26.             background-color: transparent;
  27.             pointer-events: none;
  28.         }
  29.         :not(select):not(hbox) > scrollbar thumb {
  30.             -moz-appearance: none!important;
  31.             background-color: transparent;
  32.             pointer-events: auto;
  33.         }
  34.         :not(select):not(hbox) > scrollbar[orient = "vertical"] {
  35.             min-width: 12px!important;
  36.             -moz-margin-start: -12px;/*margin to fill the whole render window with content and overlay the scrollbars*/
  37.         }
  38.         :not(select):not(hbox) > scrollbar[orient = "horizontal"] {
  39.             height: 12px!important;
  40.             margin-top: -12px;
  41.         }
  42.         :not(select):not(hbox) > scrollbar[orient = "vertical"] thumb {
  43.             border-right: 2px solid rgba(133, 132, 131, 1);
  44.             width: 12px;
  45.             min-height: 12px;
  46.             transition: border 0.1s ease-in;
  47.         }
  48.         :not(select):not(hbox) > scrollbar[orient = "horizontal"] thumb {
  49.             border-bottom: 2px solid rgba(133, 132, 131, 1);
  50.             min-width: 12px;
  51.             transition: border 0.1s ease-in;
  52.         }
  53.         :not(select):not(hbox) > scrollbar:hover {
  54.             background-color: rgba(0, 0, 0, 0.25);
  55.             max-width: 12px!important;
  56.             point-events: auto;
  57.         }
  58.         :not(select):not(hbox) > scrollbar:hover thumb {
  59.             border-width: 12px;
  60.             transition: border 0s linear;
  61.         }
  62.         :not(select):not(hbox) > scrollbar scrollbarbutton, :not(select):not(hbox) > scrollbar gripper {
  63.             display: none;
  64.         }
  65.     `;
  66.  
  67.     var sss = Cc['@mozilla.org/content/style-sheet-service;1'].getService(Ci.nsIStyleSheetService);
  68.     var uri = makeURI('data:text/css;charset=UTF=8,' + encodeURIComponent(css));
  69.  
  70.     var p = document.getElementById('devToolsSeparator');
  71.     var m = document.createElement('menuitem');
  72.     m.setAttribute('label', "Windows 10 Style Scrollbars");
  73.     m.setAttribute('type', 'checkbox');
  74.     m.setAttribute('autocheck', 'false');
  75.     m.setAttribute('checked', enabled);
  76.     p.parentNode.insertBefore(m, p);
  77.     m.addEventListener('command', command, false);
  78.  
  79.     if (enabled) {
  80.         sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
  81.     }
  82.  
  83.     function command() {
  84.         if (sss.sheetRegistered(uri, sss.AGENT_SHEET)) {
  85.             prefs.setBoolPref('userChromeJS.floating_scrollbar.enabled', false);
  86.             sss.unregisterSheet(uri, sss.AGENT_SHEET);
  87.             m.setAttribute('checked', false);
  88.         } else {
  89.             prefs.setBoolPref('userChromeJS.floating_scrollbar.enabled', true);
  90.             sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
  91.             m.setAttribute('checked', true);
  92.         }
  93.  
  94.         let root = document.documentElement;
  95.         let display = root.style.display;
  96.         root.style.display = 'none';
  97.         window.getComputedStyle(root).display; // Flush
  98.         root.style.display = display;
  99.     }
  100.  
  101. })();
Add Comment
Please, Sign In to add comment