.attr()
500 以上のステートメントを実行しないでください。ページを処理するより効率的な方法を使用します。
次のように 2 つのファイルを作成します。
old_URLs.js:
var oldUrlArray = [
"Old address 1",
"Old address 2",
"Old address 3",
// etc., etc.
]
new_URLs.js:
var newUrlArray = [
"New address 1",
"New address 2",
"New address 3",
// etc., etc.
]
.user.js
gmファイルと同じフォルダに配置します。
次に、スクリプトは次のようになります。
// ==UserScript==
// @name _Mass link replacer remapper
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require old_URLs.js
// @require new_URLs.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
var oldLinks = $('a[href*="pattern-of-old-cms"]');
while (oldLinks.length) {
var firstHref = oldLinks[0].href;
var hrefIndex = oldUrlArray.indexOf (firstHref);
if (hrefIndex >= 0) {
var toReplace = oldLinks.filter ("[href='" + firstHref + "']");
toReplace.attr ("href", newUrlArray[hrefIndex]);
oldLinks = oldLinks.not (toReplace);
}
else {
alert ("I don't know how to map the link: " + firstHref);
break;
}
}