Wayback Machine - toolbar toggler

A way to toggle the WaybackMachine's toolbar

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

  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.1
  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. // @match http://web.archive.org/web/*
  11. // @grant none
  12. // @run-at document-start
  13. // @noframes
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. "use strict";
  18.  
  19. function addStyle(e,s) {
  20. if (!e) return;
  21. var st=document.createElement("style");
  22. st.textContent=s;
  23. e.appendChild(st);
  24. }
  25.  
  26. function fix(ev) {
  27. var TO, st, sts = document.getElementsByTagName('style');
  28. 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;}')
  29.  
  30. // remove this style if present
  31. for (st of sts) {
  32. if (st.innerText.search('.wb-autocomplete-suggestions')+1) {
  33. st.innerText='';
  34. break;
  35. }
  36. }
  37.  
  38. // remove all added styles
  39. var wbSt, del=[];
  40. for (let el of document.body.childNodes) {
  41. if (el.nodeType==8) {
  42. if (!wbSt && (el.data==' BEGIN WAYBACK TOOLBAR INSERT ')) wbSt=true;
  43. else if (wbSt && (el.data==' END WAYBACK TOOLBAR INSERT ')) {
  44. for (let i in del) del[i].parentNode.removeChild(del[i]);
  45. break;
  46. }
  47. continue;
  48. }
  49. if (!wbSt) continue;
  50. if (el.nodeName=='STYLE') del.push(el);
  51. }
  52.  
  53. // remove archive.org stylesheets
  54. sts=document.querySelectorAll('link[rel=stylesheet]');
  55. for (st of sts) {
  56. if (st.href.startsWith('https://web.archive.org/_static/') && !(st.href.search('/iconochive.css')+1) ) {
  57. st.parentNode.removeChild(st);
  58. }
  59. }
  60.  
  61. // change "close" icon color
  62. if (!sr) sr=e.sr;
  63. addStyle(sr,'#wm-tb-close .iconochive-remove-circle {color: #26d926 !important;}');
  64.  
  65. this.removeEventListener('dblclick', fix);
  66. document.body.addEventListener('keydown',function(ev){
  67. force=ev.altKey && ev.ctrlKey;
  68. if (force && !forceState) {
  69. e.classList.add('forcePriority');
  70. forceState=force;
  71. if (TO) clearTimeout(TO);
  72. TO=setTimeout(function(){
  73. e.classList.remove('forcePriority');
  74. forceState=false;
  75. TO=0;
  76. },3000);
  77.  
  78. if (sr && (sr.firstChild.style.display=='none') ) {
  79. sr.firstChild.style.display='';
  80. }
  81. }
  82. });
  83. }
  84.  
  85. var e=document.getElementById('wm-ipp-base'), initCnt=300, sr, force=false, forceState=false;
  86.  
  87. function init() {
  88. e=document.getElementById('wm-ipp-base');
  89. if (!e) {
  90. if (--initCnt > 0) setTimeout(init, 0);
  91. else if (initCnt > -5) setTimeout(init, 3000);
  92. return;
  93. }
  94.  
  95. // intercept shadow and store "sr"
  96. var oldAS=e.attachShadow;
  97. e.attachShadow=function(m){
  98. sr=oldAS.call(e,m);
  99. return sr;
  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. })();