Greasy Fork Install Button at search

adds install button at search and at user pages.

目前為 2022-04-28 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/*

﹀ Change Log ﹀

0.5.0 Version:
- jQuery to Pure JS

0.4.1-extra Version:
- Added libraries support at user pages

0.4 Version:
- Removed HTTP support
- Added libraries support

0.3 Version:
- SleazyFork support
- HTTP support

0.2 Version:
- Better css styles identifying

*/

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

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

Element.prototype.appendHTML = function(html) {
    this.insertAdjacentHTML('beforeend', html)
}

var domain = location.host

// STYLES
$('head').appendHTML(`<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>`)

// 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) {
    let scriptId = e.parentNode.parentNode.parentNode.dataset.scriptId, scriptName = e.parentNode.parentNode.parentNode.dataset.scriptName
    e.appendHTML('<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) {
    let scriptId = e.parentNode.parentNode.parentNode.dataset.scriptId
    let scriptName = e.parentNode.parentNode.parentNode.dataset.scriptName
    e.appendHTML('<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) {
    let scriptId = e.parentNode.parentNode.parentNode.dataset.scriptId, scriptName = e.parentNode.parentNode.parentNode.dataset.scriptName, scriptNameFinal = scriptName.replace(/\s/g, "-")
    e.appendHTML('<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/' + scriptNameFinal + '.js") class="custom-install-link-parent"><span class="install-link custom-install-link">Copy URL</span></a><span>')
})