Change all language page to specific language result page.
Per
// ==UserScript==
// @name:ko Hitomi 언어 설정
// @name Hitomi Language Settings
// @name:ja Hitomi言語設定
// @name:zh-TW Hitomi語言設置
// @name:zh-CN Hitomi语言设置
// @description:ko 모든 언어 페이지를 특정 언어 결과 페이지로 변경합니다.
// @description Change all language page to specific language result page.
// @description:ja すべての言語ページを特定の言語結果ページに変更します。
// @description:zh-TW 將所有語言頁面更改爲特定語言結果頁面。
// @description:zh-CN 将所有语言页面更改为特定语言结果页面。
// @namespace https://ndaesik.tistory.com/
// @version 2022.07.29.04.29
// @author ndaesik & SFGFDSD(修改)
// @icon https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://hitomi.la
// @match https://hitomi.la/*
// @grant GM.getValue
// @grant GM.setValue
// @grant GM_registerMenuCommand
// @grant GM_addStyle
// ==/UserScript==
(async () => {
let cst = (await GM.getValue('custom')).toLowerCase()
, nav = {zh:'chinese',ja:'japanese',en:'english',ko:'korean'}
, txt = (cst == '') ? nav[window.navigator.language.substring(0,2)] : cst
, mov = _ => {window.location = window.location.toString().replace(/-all\./, `-${txt}\.`)}
, tar = document.querySelector('#lang > a');
// 手机端处理
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
// 设置语言选择按钮
if (tar) {
tar.href = `https://hitomi.la/index-${txt}.html`
tar.innerHTML = `${txt}<img src="//ltn.hitomi.la/down-arrow.png">`
tar.style.cssText = 'padding: 0 10px; width: 150px; display: inline-block'
tar.addEventListener('click', function(event) {
event.preventDefault(); // 阻止默认行为
setLanguage(txt); // 设置语言
});
}
}
// 电脑端处理
else {
let languageButton = document.createElement('button');
languageButton.textContent = '设置语言';
languageButton.id = 'languageButton';
languageButton.addEventListener('click', function() {
setLanguage(txt);
});
document.body.appendChild(languageButton);
}
// 设置语言
function setLanguage(language) {
GM.setValue('custom', language).then(() => {
window.location.reload();
});
}
})();