Wayback Machine - toolbar toggler

A way to toggle the WaybackMachine's toolbar

目前为 2020-05-06 提交的版本。查看 最新版本

  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.6.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. // @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.innerText=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. addStyle(sr,'#wm-tb-close .iconochive-remove-circle {color: #26d926 !important;}');
  62.  
  63. this.removeEventListener('dblclick', fix);
  64. document.body.addEventListener('keydown',function(ev){
  65. force=ev.altKey && ev.ctrlKey;
  66. if (force && !forceState) {
  67. e.classList.add('forcePriority');
  68. forceState=force;
  69. if (TO) clearTimeout(TO);
  70. TO=setTimeout(function(){
  71. e.classList.remove('forcePriority');
  72. forceState=false;
  73. TO=0;
  74. },3000);
  75.  
  76. if (sr && (sr.firstChild.style.display=='none') ) {
  77. sr.firstChild.style.display='';
  78. }
  79. }
  80. });
  81. }
  82.  
  83. var e=document.getElementById('wm-ipp-base'), initCnt=300, sr, force=false, forceState=false;
  84.  
  85. function init() {
  86. e=document.getElementById('wm-ipp-base');
  87. if (!e) {
  88. if (--initCnt > 0) setTimeout(init, 1);
  89. else if (initCnt > -5) setTimeout(init, 3000);
  90. return;
  91. }
  92.  
  93. // intercept shadow and store "sr"
  94. var oldAS=e.attachShadow;
  95. e.attachShadow=function(m){
  96. sr=oldAS.call(e,m);
  97. return sr;
  98. }
  99.  
  100. e.addEventListener('dblclick', fix);
  101. let ne=e.nextElementSibling;
  102. if (ne && (ne.id=='donato')) ne.parentNode.removeChild(ne);
  103. }
  104. init();
  105.  
  106. })();