Wayback Machine - toolbar toggler

A way to toggle the WaybackMachine's toolbar

目前為 2020-05-09 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Wayback Machine - toolbar toggler
// @name:fr      Wayback Machine - (dé)masquer la barre d'outils
// @namespace    https://github.com/Procyon-b
// @version      0.7
// @description  A way to toggle the WaybackMachine's toolbar
// @description:fr  Une méthode pour masquer/afficher la barre d'outils de WaybackMachine (web.archive.org)
// @author       Achernar
// @match        https://web.archive.org/web/*
// @grant        none
// @run-at       document-start
// @noframes
// ==/UserScript==

(function() {
"use strict";

function addStyle(e,s) {
  if (!e) return;
  var st=document.createElement("style");
  st.textContent=s;
  e.appendChild(st);
  }

function fix(ev) {
  var TO, st, sts = document.getElementsByTagName('style');
  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;}')

  // remove this style if present
  for (st of sts) {
    if (st.innerText.search('.wb-autocomplete-suggestions')+1) {
      st.innerText='';
      break;
      }
    }

  // remove all added styles
  var wbSt, del=[];
  for (let el of document.body.childNodes) {
    if (el.nodeType==8) {
      if (!wbSt && (el.data==' BEGIN WAYBACK TOOLBAR INSERT ')) wbSt=true;
      else if (wbSt && (el.data==' END WAYBACK TOOLBAR INSERT ')) {
        for (let i in del) del[i].parentNode.removeChild(del[i]);
        break;
        }
      continue;
      }
    if (!wbSt) continue;
    if (el.nodeName=='STYLE') del.push(el);
    }

  // remove archive.org stylesheets
  sts=document.querySelectorAll('link[rel=stylesheet]');
  for (st of sts) {
    if (st.href.startsWith('https://web.archive.org/_static/') && !(st.href.search('/iconochive.css')+1) ) {
      st.parentNode.removeChild(st);
      }
    }

  // change "close" icon color
  if (!sr) sr=e.sr;
  addStyle(sr,'#wm-tb-close .iconochive-remove-circle {color: #26d926 !important;}');

  this.removeEventListener('dblclick', fix);
  document.body.addEventListener('keydown',function(ev){
    force=ev.altKey && ev.ctrlKey;
    if (force && !forceState) {
      e.classList.add('forcePriority');
      forceState=force;
      if (TO) clearTimeout(TO);
      TO=setTimeout(function(){
        e.classList.remove('forcePriority');
        forceState=false;
        TO=0;
        },3000);

      if (sr && (sr.firstChild.style.display=='none') ) {
        sr.firstChild.style.display='';
        }
      }
    });
  }

var e=document.getElementById('wm-ipp-base'), initCnt=300, sr, force=false, forceState=false;

function init() {
  e=document.getElementById('wm-ipp-base');
  if (!e) {
    if (--initCnt > 0) setTimeout(init, 0);
    else if (initCnt > -5) setTimeout(init, 3000);
    return;
    }

  // intercept shadow and store "sr"
  var oldAS=e.attachShadow;
  e.attachShadow=function(m){
    sr=oldAS.call(e,m);
    return sr;
    }

  e.addEventListener('dblclick', fix);
  let ne=e.nextElementSibling;
  if (ne && (ne.id=='donato')) ne.parentNode.removeChild(ne);
  }
init();

// catch attachShadow
var s=document.createElement('script');
s.textContent=`(function(){
var options={attributes: false, subtree: true, childList: true };
var obs = new MutationObserver(function(mutL) {
  for (let mut of mutL) {
    let e=mut.addedNodes[0];
    if (e.id=='wm-ipp-base') {
      var oldAS=e.attachShadow;
      e.attachShadow=function(m){
        e.sr=oldAS.call(e,m);
        return e.sr;
        }
      obs.disconnect();
      }
    }
});
obs.observe(document.documentElement, options);
})()`;
var sc=document.documentElement.insertBefore(s,document.head);
sc.parentNode.removeChild(sc);

})();