私はGreasemonkeyスクリプト(ここでは元のスレッド:<head>内のJavascriptコメントを取得するJavascript)を持っており、Webページ(CMSがページにスタンプするPageID)から文字列を取得します。この文字列はGreasemonkeyを使用してブラウザに表示されます。これの目的はウェブサイトのメンテナンスであり、ウェブサイトを閲覧して特定のページのPageIDをすばやく確認できます。これを実現するために使用されるコードは次のとおりです。
var commentNode = [].slice.call(document.head.childNodes).filter(function(node) {
return node.nodeType == 8;
})[0],
id = commentNode.data.match(/^\s*(\d+)/)[1];
var elem = document.createElement('div');
elem.id = 'id-display';
elem.appendChild(document.createTextNode(id));
document.body.appendChild(elem);
GM_addStyle = function(css) {
var head = document.getElementsByTagName('head')[0], style = document
.createElement('style');
if (!head) {
return
}
style.type = 'text/css';
style.textContent = css;
head.appendChild(style);
}
これは私のブラウザ(ChromeまたはFirefox w / Greasemonkey)に次のように表示されます。
Page ID: 0001
これで、CMSから次の形式で公開する別のHTMLレポートができました。
<table class="report-table">
<thead>
<tr>
<th scope="col">Page Id</th>
<th scope="col">Page title</th>
<th scope="col">Page URL</th>
<th scope="col">Content Editor</th>
<th scope="col">Content manager</th>
<th scope="col">Date updated</th>
</tr>
</thead>
<tr>
<td>0001</td>
<td>Webpage title</td>
<td><a href="http://www.website.com/page01.htm">www.website.com/page01.htm</a></td>
<td>Joe Bloggs</td>
<td>Sussan Smith</td>
<td>01/11/2012</td>
</tr>
</table>
このWebページのレポートは、内部的にアクセス可能な場所\ internal-pc\cms-report.htmlに保存されます。
私が今やりたいのは、GreasemonkeyがまだPageID文字列を取得し、cms-report.htmlのテーブルに対してこのPageIDを検索し、この情報をGreasemonkeyオーバーレイに次のように表示することです。
Page ID: 0001
Page title: Webpage title
Page URL: www.website.com/page01.htm
Content Editor: Joe Bloggs
Content manager: Sussan Smith
Date Updated: 01/11/2012
誰かが私を正しい道に導くことができますか?