Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Wayback Google
- // @version 0.6
- // @author zanetu
- // @namespace http://userscripts.org/users/92143
- // @description Adds WayBackMachine (archive.org) links to Google search results and automatically redirects to WayBackMachine when the Google "Cached" link fails (e.g. 404 error).
- // @include /^https?://www\.google\./
- // @include /^https?://webcache\.googleusercontent\./
- // @license GPL version 2 or any later version; http://www.gnu.org/licenses/gpl-2.0.txt
- // @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
- // @supportURL https://github.com/zanetu
- // @attribution changes [d:10.06.20][u:<ul><li>added...@supportURL</li></ul>]
- // @attribution changes [d:10.04.20][u:<ul><li>Discussion on updating script: https://greasyfork.org/en/discussions/greasyfork/63969</li></ul>]
- // @grant GM_addStyle
- // @run-at document-end
- // ==/UserScript==
- //google search
- if('webcache' != location.hostname.split('.')[0]) {
- //do not run in frames or iframes
- if (window.top == window.self) {
- function modifyGoogle() {
- //add wayback machine archive links
- $('cite').each(function() {
- //legacy, esp. news
- var $firstA = $(this).parent().prev('a')
- if(!$firstA.length) {
- //legacy, esp. maps
- $firstA = $(this).prev().children('a:first-child')
- }
- if(!$firstA.length) {
- $firstA = $(this).closest('.g').find('a:first')
- }
- if($firstA.length && !$firstA.hasClass('wayback')) {
- $firstA.addClass('wayback')
- var $container = $(this).parent()
- var leftMargin = '0px'
- if('crc' == $container.children(':last').attr('class')) {
- leftMargin = '16px'
- }
- $container
- .append(' ')
- .append(
- $('<a/>')
- // Azazello - change 'http' to 'https'
- .attr('href', 'https://web.archive.org/web/' + $firstA.attr('href'))
- .html('Wayback').attr('class', 'fl _Zkb wayback')
- .css({'margin-left':leftMargin, 'display':'inline'})
- )
- .append(' ')
- }
- })
- }
- //prevent knowledge graph from disabling wayback links
- GM_addStyle('#center_col {z-index:1;}')
- MutationObserver = window.MutationObserver || window.WebKitMutationObserver
- if(MutationObserver) {
- var observer = new MutationObserver(function(mutations) {
- modifyGoogle()
- })
- //tiny delay needed for firefox
- setTimeout(function() {
- if(1 == $('#main').length) {
- observer.observe($('#main').get(0), {
- childList: true,
- subtree: true
- })
- }
- modifyGoogle()
- }, 100)
- }
- //for chrome v18-, firefox v14-, internet explorer v11-, opera v15- and safari v6-
- else {
- setInterval(function() {
- modifyGoogle()
- }, 500)
- }
- }
- }
- //google cache
- else {
- //cache miss
- if(1 === $('code:contains("/search?q=cache:")').length) {
- var link = decodeURIComponent(/\=cache\:.*?\:([^\+]+)/.exec(location.search)[1] || '')
- // Azazello - change 'http' to 'https'
- link && location.replace('https://web.archive.org/web/' + link)
- }
- }
Add Comment
Please, Sign In to add comment