🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

USO - add USOa button on userstyle page

Add a link on userstyles.org to the copy of the current userstyle on "USO archive" (uso.kkx.one)

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         USO - add USOa button on userstyle page
// @namespace    github.com/Procyon-b
// @version      0.4
// @description  Add a link on userstyles.org to the copy of the current userstyle on "USO archive" (uso.kkx.one)
// @author       Achernar
// @match        https://userstyles.org/*
// @grant        none
// ==/UserScript==

(function() {
"use strict";

var newL=document.querySelector('#__next');

if (newL) {
  let pushState=history.pushState;
  history.pushState=function(){
    pushState.apply(history, arguments);
    if (location.pathname.startsWith('/styles/')) {
      setTimeout(add, 0);
      }
    }
  // popup created?
  new MutationObserver(function(mutations) {
    if (newL.querySelector(':scope > [class^="style_mainWrapper_"]')) setTimeout(add, 0);
    }).observe(newL, { attributes: false, subtree: false, childList: true });
  }

const obs=new MutationObserver(function(muts){
  for (let mut of muts) {
    for (let n of mut.addedNodes) {
      b=n && n.querySelector && ( n.querySelector('#top-buttons > .left') || n.querySelector('#buttons') || n.querySelector('div[class^="style-details_bottomRight_"]') );
      if (b) {
        this.disconnect();
        setTimeout(addLink,0);
        return;
        }
      }
    }
  });

var b=null;

function add() {
  var e;
  if (e=document.getElementById('USOa')) {
    // update url
    e.firstElementChild.href=aLink();
    return;
    }

  b=document.querySelector('#top-buttons > .left') || document.querySelector('#buttons') || document.querySelector('div[class^="style-details_bottomRight_"]');

  if (b) addLink();
  else if (!newL) obs.observe(document.body, {attributes: false, subtree: true, childList: true });
  }

if (location.pathname.startsWith('/styles/')) add();

// old design - buttons can be removed
window.addEventListener('resize', function(){
  setTimeout(add,0);
  })

function aLink() {
  return 'https://uso.kkx.one/style/'+location.pathname.split('/')[2];
  }

function addLink() {
  if (!b || document.getElementById('USOa')) return;
  var L=aLink(),
    r=document.querySelector('div[class^="style-details_bottomRight_"]'),
    e=document.createElement('style');
  b.appendChild(e);
  e.innerText='.upgradeButton {margin-right: 11px;} #USOa {background: #39c739; color: white; text-align: center; order: 9; width: unset; padding: 0 1em; border-radius: 24px; border: none;} #USOa a {color: inherit; line-height: 1.3em} #style-top-upvotes-wrapper {white-space: nowrap;} #style-top-upvotes-wrapper.can-vote {position: relative;} #style-top-upvotes-wrapper.can-vote:hover .button-wrapper {display: flex !important; visibility: hidden;} #style-top-upvotes-wrapper.can-vote .button-wrapper ~ img {position: absolute !important; right: 0;}';
  if (r) {
    e.innerText+='\ndiv[class^="style-details_bottomRight_"] {display: flex; align-items: center;} #USOa {order: 9; z-index: 20; margin-left: 0.5em; font-size: 13px;}';
    }
  e=document.createElement('div');
  b.appendChild(e);
  e.outerHTML='<div class="customize_style_button" id="USOa"><a href="'+L+'" target="_blank"><span>Install&nbsp;from<br>USO&nbsp;archive</span></a></div>';
  }

})();