Wayback Machine - toolbar toggler

A way to toggle the WaybackMachine's toolbar

当前为 2020-05-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Wayback Machine - toolbar toggler
  3. // @name:fr Wayback Machine - (dé)masquer la barre d'outils
  4. // @namespace https://github.com/Procyon-b
  5. // @version 0.7
  6. // @description A way to toggle the WaybackMachine's toolbar
  7. // @description:fr Une méthode pour masquer/afficher la barre d'outils de WaybackMachine (web.archive.org)
  8. // @author Achernar
  9. // @match https://web.archive.org/web/*
  10. // @grant none
  11. // @run-at document-start
  12. // @noframes
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. "use strict";
  17.  
  18. function addStyle(e,s) {
  19. if (!e) return;
  20. var st=document.createElement("style");
  21. st.textContent=s;
  22. e.appendChild(st);
  23. }
  24.  
  25. function fix(ev) {
  26. var TO, st, sts = document.getElementsByTagName('style');
  27. addStyle( (document.head || document.documentElement), '#wm-ipp-base {opacity:0; min-height:1px;position:absolute;} #wm-ipp-base:hover {opacity: 1;} #wm-ipp-base.forcePriority {oposition:relative; z-index:99999;}')
  28.  
  29. // remove this style if present
  30. for (st of sts) {
  31. if (st.innerText.search('.wb-autocomplete-suggestions')+1) {
  32. st.innerText='';
  33. break;
  34. }
  35. }
  36.  
  37. // remove all added styles
  38. var wbSt, del=[];
  39. for (let el of document.body.childNodes) {
  40. if (el.nodeType==8) {
  41. if (!wbSt && (el.data==' BEGIN WAYBACK TOOLBAR INSERT ')) wbSt=true;
  42. else if (wbSt && (el.data==' END WAYBACK TOOLBAR INSERT ')) {
  43. for (let i in del) del[i].parentNode.removeChild(del[i]);
  44. break;
  45. }
  46. continue;
  47. }
  48. if (!wbSt) continue;
  49. if (el.nodeName=='STYLE') del.push(el);
  50. }
  51.  
  52. // remove archive.org stylesheets
  53. sts=document.querySelectorAll('link[rel=stylesheet]');
  54. for (st of sts) {
  55. if (st.href.startsWith('https://web.archive.org/_static/') && !(st.href.search('/iconochive.css')+1) ) {
  56. st.parentNode.removeChild(st);
  57. }
  58. }
  59.  
  60. // change "close" icon color
  61. if (!sr) sr=e.sr;
  62. addStyle(sr,'#wm-tb-close .iconochive-remove-circle {color: #26d926 !important;}');
  63.  
  64. this.removeEventListener('dblclick', fix);
  65. document.body.addEventListener('keydown',function(ev){
  66. force=ev.altKey && ev.ctrlKey;
  67. if (force && !forceState) {
  68. e.classList.add('forcePriority');
  69. forceState=force;
  70. if (TO) clearTimeout(TO);
  71. TO=setTimeout(function(){
  72. e.classList.remove('forcePriority');
  73. forceState=false;
  74. TO=0;
  75. },3000);
  76.  
  77. if (sr && (sr.firstChild.style.display=='none') ) {
  78. sr.firstChild.style.display='';
  79. }
  80. }
  81. });
  82. }
  83.  
  84. var e=document.getElementById('wm-ipp-base'), initCnt=300, sr, force=false, forceState=false;
  85.  
  86. function init() {
  87. e=document.getElementById('wm-ipp-base');
  88. if (!e) {
  89. if (--initCnt > 0) setTimeout(init, 0);
  90. else if (initCnt > -5) setTimeout(init, 3000);
  91. return;
  92. }
  93.  
  94. // intercept shadow and store "sr"
  95. var oldAS=e.attachShadow;
  96. e.attachShadow=function(m){
  97. sr=oldAS.call(e,m);
  98. return sr;
  99. }
  100.  
  101. e.addEventListener('dblclick', fix);
  102. let ne=e.nextElementSibling;
  103. if (ne && (ne.id=='donato')) ne.parentNode.removeChild(ne);
  104. }
  105. init();
  106.  
  107. // catch attachShadow
  108. var s=document.createElement('script');
  109. s.textContent=`(function(){
  110. var options={attributes: false, subtree: true, childList: true };
  111. var obs = new MutationObserver(function(mutL) {
  112. for (let mut of mutL) {
  113. let e=mut.addedNodes[0];
  114. if (e.id=='wm-ipp-base') {
  115. var oldAS=e.attachShadow;
  116. e.attachShadow=function(m){
  117. e.sr=oldAS.call(e,m);
  118. return e.sr;
  119. }
  120. obs.disconnect();
  121. }
  122. }
  123. });
  124. obs.observe(document.documentElement, options);
  125. })()`;
  126. var sc=document.documentElement.insertBefore(s,document.head);
  127. sc.parentNode.removeChild(sc);
  128.  
  129. })();