SearX: Link to proxified image

changes original href link of the image to proxified. Instances list updates automatically every 2 weeks

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name SearX: Link to proxified image
// @namespace -
// @version 1.1.0
// @description changes original href link of the image to proxified. Instances list updates automatically every 2 weeks
// @author NotYou
// @match *://*/*
// @grant GM.xmlHttpRequest
// @grant GM.setValue
// @grant GM.getValue
// @connect searx.space
// @run-at document-start
// @license GPL-3.0
// ==/UserScript==

!async function () {
    'use strict';

    const getLinkNode = node => {
        if (node.tagName.toLowerCase() === 'a') {
            return node
        } else if (node.tagName.toLowerCase() === 'html' || !node.tagName) {
            return null
        }

        return getLinkNode(node.parentNode)
    }

    const getInstances = async () => {
        return new Promise(async (resolve, reject) => {
            const instances = await GM.getValue('instances', {})
            const instancesLastUpdate = await GM.getValue('instancesLastUpdate', '1970-01-01T00:00:00.000Z')
            const instancesLastUpdateDate = new Date(instancesLastUpdate)

            instancesLastUpdateDate.setDate(instancesLastUpdateDate.getDate() + 14)

            const currentDate = new Date()

            if (currentDate > instancesLastUpdateDate) {
                GM.xmlHttpRequest({
                    url: 'https://searx.space/data/instances.json',
                    responseType: 'json',
                    onload: async ({ response }) => {
                        const instances = Object.keys(response.instances)

                        await GM.setValue('instances', instances)
                        await GM.setValue('instancesLastUpdate', currentDate.toJSON())

                        resolve(instances)
                    },
                    onerror: reject
                })
            } else {
                return resolve(null)
            }
        })
    }

    const instances = await getInstances()

    if (instances === null) return

    const foundHost = instances.find(instance => instance.includes(location.host))

    if (typeof foundHost === 'undefined') return

    document.querySelectorAll('.img-thumbnail, .image-thumbnail, .image_thumbnail').forEach($imageThumb => {
        const $link = getLinkNode($imageThumb)

        if ($link === null) return

        $link.href = $imageThumb.src
    })
}()