Skip to content

Instantly share code, notes, and snippets.

@noromanba
Last active April 14, 2016 03:39
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 noromanba/5d8a97bc1f3815c38b19e92ae13d7939 to your computer and use it in GitHub Desktop.
Save noromanba/5d8a97bc1f3815c38b19e92ae13d7939 to your computer and use it in GitHub Desktop.
canonical blogger TLD for UserScript
// ==UserScript==
// @name blogger canonical
// @namespace http://noromanba.flavors.me
// @description canonical blogger TLD for UserScript
// @include *://*.blogspot.tld/*
// @grant none
// @noframes
// @run-at document-start
// @version 2016.04.14.0
// @homepage https://gist.github.com/noromanba/5d8a97bc1f3815c38b19e92ae13d7939
// @downloadURL https://gist.github.com/noromanba/5d8a97bc1f3815c38b19e92ae13d7939/raw/blogger-canonical.user.js
// @license MIT License http://nrm.mit-license.org/2016
// @author noromanba http://noromanba.flavors.me
// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/3/32/New_Zealand_Permanent_Warning_-_Merging_Traffic_Left_and_Right.svg/32px-New_Zealand_Permanent_Warning_-_Merging_Traffic_Left_and_Right.svg.png
// @icon64 https://upload.wikimedia.org/wikipedia/commons/thumb/3/32/New_Zealand_Permanent_Warning_-_Merging_Traffic_Left_and_Right.svg/64px-New_Zealand_Permanent_Warning_-_Merging_Traffic_Left_and_Right.svg.png
// ==/UserScript==
// Icon (PD by New Zealand Transport Agency)
// https://commons.wikimedia.org/wiki/File%3ANew_Zealand_Permanent_Warning_-_Merging_Traffic_Left_and_Right.svg
// Devel
// https://gist.github.com/noromanba/5d8a97bc1f3815c38b19e92ae13d7939
// c.f.
// https://support.google.com/blogger/answer/2402711
(() => {
// /\.blogspot\.com$/ w/ @include *://*.blogspot.tld/* invoke redirect loop; e.g.
// http://b.hatena.ne.jp/entry/googlechromereleases.blogspot.com/
const [
blogger, tld
] = location.hostname.match(/\.blogspot(\.[\a-z]{2,3}(?:\.[\a-z]{2})*)$/) || '';
if (!blogger || tld === '.com') return;
// NCR: No Country Redirect
// access to below address, so set HTTP only cookie "NCR=1"
// http://<BLOGNAME>.blogspot.com/ncr/[<PATH>]
const canon = new URL(location.href);
canon.hostname = location.hostname.split('.').slice(0, 2).join('.') + '.com';
canon.pathname = '/ncr' + location.pathname;
location.href = canon.href;
})();
// NOTE
// location assertion; RegExp w/ Magic TLD within @include and @match
//
// Greasemonkey is a de facto standard; c.f.
// http://wiki.greasespot.net/Include_and_exclude_rules#Regular_Expressions
// http://wiki.greasespot.net/Include_and_exclude_rules#Magic_TLD
// http://wiki.greasespot.net/Magic_TLD
// http://wiki.greasespot.net/Metadata_Block#.40match
// https://developer.chrome.com/extensions/match_patterns
//
// Tampermonkey doesn't work Magic TLD w/ @match and @include; e.g.
// @match *://*.blogspot.tld/*
// @include /^https?:\/\/[\w\-]+\.blogspot.tld\/.*/
// @include /^https?://[\w+\-]\.blogspot.tld\/.*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment