Redirect es to ca

Tries to redirect any url with /es or es. to /ca ca.

当前为 2023-06-17 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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)
    }
  }
})()