Greasy Fork Install Button at search

adds install button at search and at user pages.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name Greasy Fork Install Button at search
// @namespace -
// @version 1.0.0
// @description adds install button at search and at user pages.
// @author NotYou
// @match *://*sleazyfork.org/*
// @match *://*greatest.deepsurf.us/*
// @grant none
// @run-at document-idle
// @license GPL-3.0-or-later
// ==/UserScript==

(function() {
    var $ = (s) => document.querySelector(s)

    var $$ = (s) => document.querySelectorAll(s)

    var appendHTML = function(el, html) {
        el.insertAdjacentHTML('beforeend', html)
    }

    var domain = location.host

    // STYLES
    appendHTML($('head'), ['<style>',

    '.custom-install-link-parent {',
      'text-decoration: none !important;',
    '}',

    '.custom-install-link-parent > * {',
      'transform: scale(0.7);',
    '}',

    '.custom-install-link {',
      'margin-right: -15px !important;',
      'margin-left: -6px !important;',
    '}',

    '.custom-install-style-link {',
      'margin-left: -14px !important;',
      'margin-right: -26px !important;',
    '}',

    '</style>'].join(''))

    // USER SCRIPT

    $$('#user-script-list > li[data-script-type="public"] > article > h2 > a, #browse-script-list > li[data-script-type="public"] > article > h2 > a').forEach(function(e) {
        var data = e.parentNode.parentNode.parentNode.dataset
        var scriptId = data.scriptId
        var scriptName = data.scriptName

        appendHTML(e, '<span data-install-format="js" data-script-id="'+ scriptId +'" data-script-name="' + scriptName + '"><a href="https://' + domain + '/scripts/' + scriptId + '/code/' + scriptName + '.user.js" class="custom-install-link-parent"><span class="install-link custom-install-link">Install</span></a><span>')
    })

    // USER STYLE

    $$('#user-script-list > li[data-script-language="css"] > article > h2 > a, #browse-script-list > li[data-script-language="css"] > article > h2 > a').forEach(function(e) {
        var data = e.parentNode.parentNode.parentNode.dataset
        var scriptId = data.scriptId
        var scriptName = data.scriptName

        appendHTML(e, '<span data-install-format="css" data-script-id="'+ scriptId +'" data-script-name="' + scriptName + '"><a target="_blank" href="https://' + domain + '/scripts/' + scriptId + '/code/' + scriptName + '.user.css" class="custom-install-link-parent"><span class="install-link custom-install-link custom-install-style-link">Install as style</span></a><span>')
    })

    // LIBRARIES

    $$('#user-library-script-list > li > article > h2 > a, #browse-script-list > li[data-script-type="library"] > article > h2 > a').forEach(function(e) {
        var data = e.parentNode.parentNode.parentNode.dataset
        var scriptId = data.scriptId
        var scriptName = data.scriptName
        var _scriptName = scriptName.replace(/\s/g, "-")

        appendHTML(e, '<span data-install-format="js" data-script-id="'+ scriptId +'" data-script-name="' + scriptName + '"><a href=javascript:void(0) onclick=navigator.clipboard.writeText("https://' + domain + '/scripts/' + scriptId + '/code/' + _scriptName + '.js") class="custom-install-link-parent"><span class="install-link custom-install-link">Copy URL</span></a><span>')
    })
})()