Guest User

Untitled

a guest
Jul 21st, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  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.  
  24. :not(select):not(hbox) > scrollbar {
  25. -moz-appearance: none!important;
  26. position: relative!important;
  27. background-color: transparent;
  28. }
  29. :not(select):not(hbox) > scrollbar thumb,
  30. :not(select):not(hbox) > scrollbar scrollbarbutton{
  31. -moz-appearance: none!important;
  32. background-color: transparent;
  33. pointer-events: auto;
  34. opacity: 0.5;
  35. transition: opacity 0.1s ease-in;
  36. }
  37. :not(select):not(hbox) > scrollbar scrollbarbutton{
  38. opacity: 0;
  39. filter: invert(100%);
  40. }
  41. scrollbarbutton[type="decrement"]{
  42. border-image-source: url("chrome://global/skin/icons/calendar-arrow-left.svg");
  43. }
  44. scrollbar[orient="vertical"] > scrollbarbutton[type="decrement"]{
  45. border-image-source: url("chrome://global/skin/icons/find-previous-arrow.svg");
  46. }
  47. scrollbarbutton[type="increment"]{
  48. border-image-source: url("chrome://global/skin/icons/calendar-arrow-right.svg");
  49. }
  50. scrollbar[orient="vertical"] > scrollbarbutton[type="increment"]{
  51. border-image-source: url("chrome://global/skin/icons/find-next-arrow.svg");
  52. }
  53. :not(select):not(hbox) > scrollbar[orient = "vertical"] thumb{
  54. border-image-source: linear-gradient(to right, transparent 12px, black 14px);
  55. border-image-width: 0 0 0 16px;
  56. border-image-slice: 0% 0% 0% 100%;
  57. border-image-repeat: stretch;
  58. }
  59. :not(select):not(hbox) > scrollbar[orient = "horizontal"] thumb{
  60. border-image-source: linear-gradient(to bottom, transparent 12px, black 14px);
  61. border-image-width: 16px 0 0 0;
  62. border-image-slice: 100% 0% 0% 0%;
  63. border-image-repeat: stretch;
  64. }
  65.  
  66. :not(select):not(hbox) > scrollbar scrollbarbutton{
  67. border-image-width: 0 0 0 12px;
  68. border-image-slice: 0% 0% 0% 84%;
  69. border-image-repeat: stretch;
  70. min-width: unset !important;
  71. min-height: 16px !important;
  72. }
  73. :not(select):not(hbox) > scrollbar[orient = "vertical"] {
  74. min-width: 16px!important;
  75. -moz-margin-start: -16px;/*margin to fill the whole render window with content and overlay the scrollbars*/
  76. }
  77. :not(select):not(hbox) > scrollbar[orient = "horizontal"] {
  78. height: 16px!important;
  79. margin-top: -16px;
  80. }
  81. :not(select):not(hbox) > scrollbar[orient = "vertical"] thumb,
  82. :not(select):not(hbox) > scrollbar[orient = "vertical"] scrollbarbutton {
  83. border-right: 16px solid rgba(133, 132, 131, 1);
  84. width: 16px;
  85. min-height: 16px;
  86. }
  87. :not(select):not(hbox) > scrollbar[orient = "horizontal"] thumb,
  88. :not(select):not(hbox) > scrollbar[orient = "horizontal"] scrollbarbutton {
  89. border-bottom: 16px solid rgba(133, 132, 131, 1);
  90. min-width: 16px !important;
  91. }
  92. :not(select):not(hbox) > scrollbar:hover {
  93. background-color: rgba(0, 0, 0, 0.25);
  94. }
  95. :not(select):not(hbox) > scrollbar:hover thumb,
  96. :not(select):not(hbox) > scrollbar:hover scrollbarbutton {
  97. opacity: 1;
  98. }
  99. :not(select):not(hbox) > scrollbar:hover thumb{
  100. border-image: none !important;
  101. }
  102.  
  103. :not(select):not(hbox) > scrollbar gripper {
  104. display: none;
  105. }
  106. `;
  107.  
  108. var sss = Cc['@mozilla.org/content/style-sheet-service;1'].getService(Ci.nsIStyleSheetService);
  109. var uri = makeURI('data:text/css;charset=UTF=8,' + encodeURIComponent(css));
  110.  
  111. var p = document.getElementById('devToolsSeparator');
  112. var m = document.createElement('menuitem');
  113. m.setAttribute('label', "Windows 10 Style Scrollbars");
  114. m.setAttribute('type', 'checkbox');
  115. m.setAttribute('autocheck', 'false');
  116. m.setAttribute('checked', enabled);
  117. p.parentNode.insertBefore(m, p);
  118. m.addEventListener('command', command, false);
  119.  
  120. if (enabled) {
  121. sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
  122. }
  123.  
  124. function command() {
  125. if (sss.sheetRegistered(uri, sss.AGENT_SHEET)) {
  126. prefs.setBoolPref('userChromeJS.floating_scrollbar.enabled', false);
  127. sss.unregisterSheet(uri, sss.AGENT_SHEET);
  128. m.setAttribute('checked', false);
  129. } else {
  130. prefs.setBoolPref('userChromeJS.floating_scrollbar.enabled', true);
  131. sss.loadAndRegisterSheet(uri, sss.AGENT_SHEET);
  132. m.setAttribute('checked', true);
  133. }
  134.  
  135. let root = document.documentElement;
  136. let display = root.style.display;
  137. root.style.display = 'none';
  138. window.getComputedStyle(root).display; // Flush
  139. root.style.display = display;
  140. }
  141.  
  142. })();
Add Comment
Please, Sign In to add comment