Wayback Machine - toolbar toggler

A way to toggle the WaybackMachine's toolbar

Ajankohdalta 3.8.2020. Katso uusin versio.

  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.3
  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;}')
  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 && (sr.firstChild.style.display=='none') ) {
  86. sr.firstChild.style.display='';
  87. }
  88. }
  89. });
  90. }
  91.  
  92. var e=document.getElementById('wm-ipp-base'), initCnt=300, sr, force=false, forceState=false;
  93.  
  94. function init() {
  95. e=document.getElementById('wm-ipp-base');
  96. if (!e) {
  97. if (--initCnt > 0) setTimeout(init, 0);
  98. else if (initCnt > -5) setTimeout(init, 3000);
  99. return;
  100. }
  101.  
  102. e.addEventListener('dblclick', fix);
  103. let ne=e.nextElementSibling;
  104. if (ne && (ne.id=='donato')) ne.parentNode.removeChild(ne);
  105. }
  106. init();
  107.  
  108. // catch attachShadow
  109. var s=document.createElement('script');
  110. s.textContent=`(function(){
  111. var options={attributes: false, subtree: true, childList: true };
  112. var obs = new MutationObserver(function(mutL) {
  113. for (let mut of mutL) {
  114. let e=mut.addedNodes[0];
  115. if (e && (e.id=='wm-ipp-base')) {
  116. var oldAS=e.attachShadow;
  117. e.attachShadow=function(m){
  118. e.sr=oldAS.call(e,m);
  119. return e.sr;
  120. }
  121. obs.disconnect();
  122. }
  123. }
  124. });
  125. obs.observe(document.documentElement, options);
  126. })()`;
  127. var sc=document.documentElement.insertBefore(s,document.head);
  128. sc.parentNode.removeChild(sc);
  129.  
  130. })();