rep2ch

2ch スレへのリンクを全て rep2ch 用に

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey to install this script.

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name            rep2ch
// @namespace       http://lowreal.net/2006/rep2ch.user.js
// @description     2ch スレへのリンクを全て rep2ch 用に
// @include         http://*.2ch.net/test/read.cgi/*
// @include         http://*.bbspink.com/test/read.cgi/*
// @version         1.0.0-20160713-1
// ==/UserScript==
//

(function () {
	// @include だと http://example.com/?http://ex.2ch.net/test/read.cgi/* にもマッチしてしまう
	var regexp = RegExp("^http://[^.]+?\.(2ch\.net|bbspink\.com)/test/read.cgi/[^/]+?/[0-9]+");
	if (!document.location.href.match(regexp)) return;

	var URL_TO = GM_getValue("url_to");
	
	var setURL = function () {
		URL_TO = prompt("Input rep2 URL.\nex. http://example.com/rep2/read.php?url=");
		GM_setValue("url_to", URL_TO);
	}
	
	if (!URL_TO || URL_TO == "") {
		setURL();
	}

	if (confirm("Open with rep2ch?")) {
		window.location = URL_TO + window.location.href;
	}


	var div = document.createElement("div");
	with (div.style) {
		border = "1px solid #000";
		margin = "0 0 0.5em 0";
		padding = "0 1em";
		background = "#fff";
	}
	
	var link = document.createElement('a');
	link.href = URL_TO + document.location.href;
	link.appendChild(document.createTextNode("Open with rep2"));
	div.appendChild(link);

	div.appendChild(document.createTextNode(" "));

	var slink = document.createElement("a");
	slink.href = "javascript:void();";
	slink.addEventListener("click", setURL, false);
	slink.addEventListener("keypress", setURL, false);
	slink.appendChild(document.createTextNode("Reset rep2 URL"));
	div.appendChild(slink);

	var refNode = document.body.firstChild;
	document.body.insertBefore(div, refNode);
})();