Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daisuke-fukuda/7dca0f06a00239f4a7c0d95e32780890 to your computer and use it in GitHub Desktop.
Save daisuke-fukuda/7dca0f06a00239f4a7c0d95e32780890 to your computer and use it in GitHub Desktop.
<script>
var newDomain = "https://www.moyashidaisuke.com"; // 新URL
var replacedStr;
var path = location.pathname;
if(path.startsWith('\/entry')){ //記事ページの時
// pathを/区切りで分解
var ary = path.split('/');
// 最後のブロックをidとして使う
replacedStr = '/' + ary[ary.length - 1];
} else {
replacedStr = '';
}
var url = newDomain + replacedStr;
// check
console.log(url);
var link = document.getElementsByTagName("link")[0];
link.href = url;
setTimeout("redirect()", 0); // 0秒後にジャンプ
function redirect(){
location.href = url;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment