Skip to content

Instantly share code, notes, and snippets.

@teramako
Created March 19, 2012 07:29
Show Gist options
  • Save teramako/2100862 to your computer and use it in GitHub Desktop.
Save teramako/2100862 to your computer and use it in GitHub Desktop.
Oracle KROWN 文書にタイトルをつける
// ==UserScript==
// @id krown_unique_title
// @name krown_unique_title
// @version 1.0
// @namespace krown の文書にタイトルをつける
// @author teramako
// @description Oracle KROWN
// @include https://krown.oracle.co.jp/krown/oisc_showDoc.do?*
// @run-at document-end
// ==/UserScript==
/*
* この変数でフォーマットを決定する
* %...% (Windowsの環境変数的)で特定のアイテムとする
* - %NO%: 文書番号
* - %DESC%: 概要
* - %DATE%: 更新日
*/
const titleFormat = "KROWN #%NO% - %DESC%";
(function() {
setTitle(titleFormat);
function setTitle(format) {
var data = getData();
document.title = format.replace(/%(\w+?)%/g, function(all, prop){
return (prop in data) ? data[prop] : "";
});
}
function getData() {
var data = {};
var tableHeaders = document.querySelectorAll("table>tbody>tr>th");
for (var i = 0; i < tableHeaders.length; ++i) {
var th = tableHeaders[i],
thText = th.textContent.trim(),
dataText = th.nextElementSibling ? th.nextElementSibling.textContent.trim() : "";
switch (thText) {
case "\u6587\u66F8\u756A\u53F7": // "文書番号"
data.NO = dataText;
break;
case "\u6700\u7D42\u66F4\u65B0\u65E5": //"最終更新日"
data.DATE = dataText;
break;
case "\u6982\u8981": //"概要"
data.DESC = dataText;
break;
}
}
return data;
}
}());
// vim: sw=2 ts=2 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment