Skip to content

Instantly share code, notes, and snippets.

@meto4d
Last active March 26, 2020 15:29
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 meto4d/d518f4fdcc08e2d7a6cde2869d1086d7 to your computer and use it in GitHub Desktop.
Save meto4d/d518f4fdcc08e2d7a6cde2869d1086d7 to your computer and use it in GitHub Desktop.
//汎用URLパターン
var URL_PATTERN = /^(\w+):\/\/((\w|\.|:)+)(\/(.*))?$/
//したらば
var SHITARABA_URL_PATTERN = /^https?:\/\/jbbs\.shitaraba\.net.*$/
var SHITARABA_THREAD_URL_PATTERN = /^https?:\/\/jbbs\.shitaraba\.net\/bbs\/read\.cgi\/(\w+)\/(\d+)\/(\d+)(:?|\/.*)$/;
var SHITARABA_BOARD_URL_PATTERN = /^https?:\/\/jbbs\.shitaraba\.net\/(\w+)\/(\d+)\/?$/;
//2ch系列
var NICHAN_THREAD_URL_PATTERN = /^https?:\/\/(?!jbbs\.shitaraba\.net)(.+)\/test\/read\.cgi\/(\w+)\/(\d+)\/(:?|\/.*)$/;
var NICHAN_BOARD_URL_PATTERN = /^https?:\/\/(?!jbbs\.shitaraba\.net)(.+)\/(\w+)\/?$/;
//複合汎用掲示板
var THREAD_URL_PATTERN = /^(\w+):\/\/([^\/]+)\/(test|bbs)\/read\.cgi\/(\w+)\/(\d+)(\/(\d+))?(:?|\/.*)$/;
var BOARD_URL_PATTERN = /^(\w+):\/\/([^\/]+)\/(\w+)(\/(\d+))?\/?$/;
var match = THREAD_URL_PATTERN.exec(CONTACT_URL);
function thread_url(match) {
var url = {};
url.protocol = match[1];
url.shitaraba = ~match[2].indexOf("shitaraba");
url.fqdn = match[2];
url.category = match[4];
url.board_num = url.shitaraba ? match[5] : "";
url.thread_id = url.shitaraba ? match[7] : match[5];
return url;
}
var match = BOARD_URL_PATTERN.exec(CONTACT_URL);
function board_url(match) {
var url = {};
url.protocol = match[1];
url.shitaraba = ~match[2].indexof("shitaraba");
url.fqdn = match[2];
url.category = match[3];
url.board_num = url.shitaraba ? match[5] : "";
return url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment