Skip to content

Instantly share code, notes, and snippets.

@yosshi
Created April 11, 2013 03:58
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 yosshi/5360635 to your computer and use it in GitHub Desktop.
Save yosshi/5360635 to your computer and use it in GitHub Desktop.
ガルーンの特定の文字列が含まれているタグ(a タグ等)を強調するためのユーザースクリプト 例: aタグ内の"メンテナンス"という文字列があるかどうか判定して強調する
// ==UserScript==
// @name garoon emphasize
// @namespace https://github.com/yosshi/garoon-emphasize
// @description garoon に表示されている文字を強調するためのスクリプト
// @include // garoon の URL
// @exclude
// ==/UserScript==
(function() {
// hash に対象と除外したい文字列の正規表現
// includeRegexp 対象にしたい文字列の正規表現
// excludeRegexp 除外したい文字列の正規表現
var settings = new Array();
settings.push(
{
'elementTagName': "a",
'includeRegexp': "メンテナンス",
'excludeRegexp': ""
}
)
// 指定された要素を目立つようにする
function emphasizeElement(e){
with(e.style){
backgroundColor = "#ff3"
borderWidth = "2px";
borderColor = "#fc0";
borderStyle = "solid";
}
}
// リンクを除外するための正規表現オブジェクトを生成
function createExcludeRegExp(excludeRegexp){
return excludeRegexp ? new RegExp(excludeRegexp) : null;
}
function createIncludeRegExp(includeRegexp){
return new RegExp(includeRegexp)
}
function emphasize(elementTagName, re, notRe){
var anchors = document.getElementsByTagName(elementTagName);
for (var i = 0; i < anchors.length; i++){
textContent = anchors[i].textContent;
if (!textContent.match(re) || textContent.match(notRe)) continue;
emphasizeElement(anchors[i]);
}
}
// main 処理実行
settings.forEach(function(setting)
{
emphasize(setting['elementTagName'],
createIncludeRegExp(setting['includeRegexp']),
createExcludeRegExp(setting['excludeRegexp']))
}
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment