Skip to content

Instantly share code, notes, and snippets.

@to
Last active June 23, 2022 04:00
Show Gist options
  • Save to/51aee273797e2b538664ed2bb57f31c3 to your computer and use it in GitHub Desktop.
Save to/51aee273797e2b538664ed2bb57f31c3 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Unity - Open Japanese Page
// @version 0.1
// @author to
// @namespace https://github.com/to
// @license MIT
//
// @match file:///C:/Program%20Files/Unity/Hub/Editor/*
// @match https://docs.unity3d.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=unity3d.com
//
// @grant GM_openInTab
// @grant GM_addStyle
// ==/UserScript==
GM_addStyle(`
a#switch-page.switch-link.gray-btn.sbtn.left{
color : white !important;
}
`);
(() => {
var href = location.href;
if (/file:\/\//.test(href)) {
let version = href.match(/Editor\/(\d{4}\.\d)/)[1];
let path = href.match(/Manual\/(.+)/)[1];
GM_openInTab(`https://docs.unity3d.com/ja/${version}/Manual/${path}`);
return;
}
if (/\/(\d{4}.+?\/)Documentation\//.test(href)) {
GM_openInTab(location.href.replace(/\/(\d{4}.+?\/)Documentation\//, '/ja/$1'));
return;
}
if (/ScriptReference\//.test(href)) {
var elmLink = document.querySelector('.switch-link.gray-btn.sbtn.left');
elmLink.classList.remove('hide');
elmLink.id = 'switch-page';
elmLink.href = href.replace('ScriptReference/', 'Manual/class-');
return;
}
if (/Manual\/(class|script)-/.test(href)) {
var elmTitle = document.querySelector('.section h1');
elmTitle.style.marginBottom = '0';
var elmLink = document.createElement('a');
elmTitle.after(elmLink);
elmLink.textContent = 'スクリプトに切り替える';
elmLink.className = 'switch-link gray-btn sbtn left';
elmLink.style.marginBottom = '2em';
elmLink.id = 'switch-page';
if (/class-/.test(href)) {
elmLink.href = href.replace('Manual/class-', 'ScriptReference/');
} else {
let name = href.match(/script-(.+)\.html/)[1];
elmLink.href = `https://docs.unity3d.com/Packages/[email protected]/api/UnityEngine.UI.${name}.html`;
}
return;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment