您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Tries to redirect any url with /es or es. to /ca ca.
当前为
- // ==UserScript==
- // @name Redirect es to ca
- // @description Tries to redirect any url with /es or es. to /ca ca.
- // @namespace https://github.com/tonioriol
- // @version 0.0.3
- // @match *://*/*
- // @grant GM.getValue
- // @grant GM.setValue
- // @license MIT
- // ==/UserScript==
- const popover = `
- <div style="position: absolute; top: 50px; left: 50px; z-index: 999999; padding: 10px 20px; color: white; background-color: black; font-size: 32px; display: flex; align-items: center; gap: 16px" onclick="this.hidden=true">
- Redirigit a la versió en català. <span style="font-size: 1.5em">✖</span>
- </div>
- `
- const notify = () => {
- const div = document.createElement('div')
- div.innerHTML = popover
- document.body.appendChild(div)
- setTimeout(() => {
- div.hidden = true
- }, 3000)
- }
- (async () => {
- window.addEventListener('load', async () => {
- const notf = await GM.getValue('notify', false)
- if (notf) {
- await GM.setValue('notify', false)
- notify()
- }
- })
- const oldHref = location.href
- const fixedHref = location.href.replace(/(\/es\/)/, '/ca/')
- if (location.href !== fixedHref) {
- const response = await fetch(fixedHref)
- if (response.ok) {
- location.href = fixedHref
- await GM.setValue('notify', true)
- }
- }
- })()