Redirect userstyles.org to uso.kkx.one (UserStyles.org Archive)

Makes userstyles.org actually usable

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Redirect userstyles.org to uso.kkx.one (UserStyles.org Archive)
// @namespace    https://greasyfork.org/users/124677-pabli
// @version      0.4
// @description  Makes userstyles.org actually usable
// @author       Pabli
// @license      MIT
// @match        http*://userstyles.org/*
// @match        http*://uso.kkx.one/*
// @run-at       document-start
// @icon         https://www.google.com/s2/favicons?sz=64&domain=https://uso.kkx.one
// @grant        none
// ==/UserScript==

if (window.location.hostname == 'userstyles.org' && window.location.search != '?noredirect') {

    let path = window.location.pathname.split('/')
    let p

    path[3] == 'newest-styles' ? p = 'browse/styles?sort=created' :
    path[3] == 'recently-updated' ? p = 'browse/styles?sort=updated' :
    path[3] == 'editors-choice' ? p = 'browse/styles?sort=rating' :
    path[2] == 'browse' && !path[3] ? p = 'browse/styles' :
    path[2] == 'browse' ? p = 'browse/styles?search=%23' + path[3] :
    path[1] == 'user-profile' ? p = 'browse/styles?search=%40' + path[2] :
    path[1] == 'categories' ? p = 'browse/categories' :
    path[1] == 'styles' ? p = 'style/' + path[2] : p = ''

    location.href = 'https://uso.kkx.one/' + p
}
// Make "View on UserStyles.org" button work without disabling the script
if (window.location.hostname == 'uso.kkx.one') {

    let observer = new MutationObserver(mutations => {
        let btn = document.querySelector('.container a[href^="https://userstyles.org/styles"]:not([href$="?noredirect"])')
        if (btn) {
            let title = document.querySelector('.container > h1').innerText
            title = title.replaceAll(/\W+/g, '-').replace(/-$/, '').toLowerCase()
            btn.href += '/' + title + '?noredirect'
        }
    })
    observer.observe(document.body, { childList: true, subtree: true })

}