Add Web Archive Button to Search Engines

Add a button to access web archive for each search result on search engine pages

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Add Web Archive Button to Search Engines
// @namespace    http://github.com/dreamking60
// @version      1.0
// @description  Add a button to access web archive for each search result on search engine pages
// @match        https://www.google.com/search*
// @match        https://www.bing.com/search*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    var searchEngine = determineSearchEngine();

    // 遍历每个搜索结果
    var searchResults = document.querySelectorAll(getSelectorForSearchEngine(searchEngine));
    searchResults.forEach(function(result) {
        // 创建一个新按钮
        var archiveButton = document.createElement('a');
        archiveButton.className = 'web-archive-button';
        archiveButton.textContent = 'Web Archive';
        archiveButton.href = 'http://web.archive.org/save/' + result.querySelector('a').href;
        archiveButton.target = '_blank';

        // 将按钮添加到搜索结果后面
        result.appendChild(archiveButton);
    });

    // 确定当前搜索引擎
    function determineSearchEngine() {
        if (window.location.hostname.includes('google.com')) {
            return 'google';
        } else if (window.location.hostname.includes('bing.com')) {
            return 'bing';
        } else {
            return 'unknown';
        }
    }

    // 获取不同搜索引擎的选择器
    function getSelectorForSearchEngine(engine) {
        switch (engine) {
            case 'google':
                return '.tF2Cxc'; // Google的选择器
            case 'bing':
                return '.b_algo'; // Bing的选择器
            default:
                return ''; // 默认选择器
        }
    }
})();