Skip to content

Instantly share code, notes, and snippets.

@mstssk
Last active April 2, 2021 10:53
Show Gist options
  • Save mstssk/277b51edba9cf46465fcd05020f6fad1 to your computer and use it in GitHub Desktop.
Save mstssk/277b51edba9cf46465fcd05020f6fad1 to your computer and use it in GitHub Desktop.
Railsの日本語ガイドへのリダイレクトリンクを表示するUserScript
// ==UserScript==
// @name Suggest Redirect from guides.rubyonrails.org to railsguides.jp
// @namespace http://tampermonkey.net/
// @version 1.1.1
// @description Railsの日本語ガイドへのリダイレクトリンクを表示する。
// @author @mstssk
// @match https://guides.rubyonrails.org/*
// @match https://railsguides.jp/*
// @grant none
// @homepageURL https://gist.github.com/mstssk/277b51edba9cf46465fcd05020f6fad1/
// @updateURL https://gist.githubusercontent.com/mstssk/277b51edba9cf46465fcd05020f6fad1/raw/redirect2railsguides.js
// @downloadURL https://gist.githubusercontent.com/mstssk/277b51edba9cf46465fcd05020f6fad1/raw/redirect2railsguides.js
// ==/UserScript==
(function () {
"use strict";
const styles = `
position: fixed;
top: 0;
padding: 4px;
background-color: rgba(256,256,256,0.9);
border-radius: 0 0 4px 0;
box-shadow: 0 0 2px 1px darkgrey;
z-index: 100;
`;
const href = document.location.href;
const en2ja = href.includes("guides.rubyonrails.org");
const url = en2ja
? href.replace("https://guides.rubyonrails.org/", "https://railsguides.jp/")
: href.replace(
"https://railsguides.jp/",
"https://guides.rubyonrails.org/"
);
const html = en2ja
? `<a rel="alternate" hreflang="ja" href="${url}">日本語</a>`
: `<a rel="alternate" hreflang="en" href="${url}">English</a>`;
const div = document.createElement("div");
div.innerHTML = html;
div.setAttribute("style", styles);
document.body.appendChild(div);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment