Wayback Machine - toolbar toggler

A way to toggle the WaybackMachine's toolbar

目前为 2022-05-22 提交的版本。查看 最新版本

  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.5
  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 *://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;} body > #wm-ipp-print, body> #donato {display: none;}');
  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=0; i<del.length; i++) 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. if (sr) {
  63. let s='#wm-tb-close .iconochive-remove-circle {color: #26d926 !important;}';
  64. try{ addStyle(sr, s);
  65. }catch(er){
  66. let st=document.createElement('style');
  67. st.textContent=s;
  68. sr.appendChild(st);
  69. }
  70. }
  71.  
  72. this.removeEventListener('dblclick', fix);
  73. document.body.addEventListener('keydown',function(ev){
  74. force=ev.altKey && ev.ctrlKey;
  75. if (force && !forceState) {
  76. e.classList.add('forcePriority');
  77. forceState=force;
  78. if (TO) clearTimeout(TO);
  79. TO=setTimeout(function(){
  80. e.classList.remove('forcePriority');
  81. forceState=false;
  82. TO=0;
  83. },3000);
  84.  
  85. if (sr) {
  86. let e = sr.querySelector('[style*="display: none;"]')
  87. if (e) e.style.display='';
  88. }
  89. }
  90. });
  91. }
  92.  
  93. var e=document.getElementById('wm-ipp-base'), initCnt=300, sr, force=false, forceState=false;
  94.  
  95. function init() {
  96. e=document.getElementById('wm-ipp-base');
  97. if (!e) {
  98. if (--initCnt > 0) setTimeout(init, 0);
  99. else if (initCnt > -5) setTimeout(init, 3000);
  100. return;
  101. }
  102.  
  103. e.addEventListener('dblclick', fix);
  104. let ne=e.nextElementSibling;
  105. if (ne && (ne.id=='donato')) ne.parentNode.removeChild(ne);
  106. }
  107. init();
  108.  
  109. // catch attachShadow
  110. var s=document.createElement('script');
  111. s.textContent=`(function(){
  112. var options={attributes: false, subtree: true, childList: true };
  113. var obs = new MutationObserver(function(mutL) {
  114. for (let mut of mutL) {
  115. let e=mut.addedNodes[0];
  116. if (e && (e.id=='wm-ipp-base')) {
  117. var oldAS=e.attachShadow;
  118. e.attachShadow=function(m){
  119. e.sr=oldAS.call(e,m);
  120. return e.sr;
  121. }
  122. obs.disconnect();
  123. }
  124. }
  125. });
  126. obs.observe(document.documentElement, options);
  127. })()`;
  128. var sc=document.documentElement.insertBefore(s,document.head);
  129. sc.parentNode.removeChild(sc);
  130.  
  131. })();