私はこれに慣れていないので、ご容赦ください。次のことを行うクロム拡張機能を作成しようとしています:
- www.website.com/anypage.html を検出します。この Web サイトが検出された場合は、次の手順を実行します。
- URL を読み込まないでください。
- 代わりに、www.website.com/anypage.html?ie=UTF8 へのハイパーリンクを含む空白のドキュメントを作成します。
スクリプトは、ドキュメントの開始時に (マニフェストで) 実行するように設定されています。
これが私のコードです:
URL の検出:
var regExp = /website.com/gi;
var match = 0;
testString = window.location.href.toString();
if(regExp.test(testString) {
match = 1;
UTF8 エンコーディング タグを使用して、URL へのリンクを含む空白のドキュメントを作成します。
document.write("<a href=" + window.location.href + "?ie=UTF8>Title of Link</a>");
これは期待どおりに機能せず、空白のページが表示されるだけです。誰にもアイデアはありますか?
ありがとう!
編集:完全なコードは次のとおりです。
checklink(); // If there is a match, then checklink will return a 1. If it's already tagged, it will return a 5.
var matchLink = null;
if (checklink() === 1) {
matchLink = window.location.href.toString();
if (checklink() != 1) {
matchLink = null;
function checklink() { //checks to see if the current URL matches website.com
var regExp = /website.com/gi,
testString = window.location.href.toString(),
match = 0,
tagged = 0;
if (regExp.test(testString)) { //if there is a match, returns 1
match = 1;
var regExp2 = /UTF8/gi;
if (regExp2.test(testString)) { //if UTF8 is found, then it returns 5
tagged = 5;
return(match + tagged);
function tagUTF() {
if (matchLink) {
var newLink = matchLink + "?ie=UTF8";
document.write("<a href=\"" + newLink + "\">Link</a>");
if (matchLink) {
tagUTF();
}