-
-
Save noromanba/3880159 to your computer and use it in GitHub Desktop.
Betterment UI and UX on Kindai Digital Lib. for Greasemonkey (not working yet)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name kindai-util | |
// @namespace https://www.hatena.ne.jp/noromanba/ | |
// @description Betterment UI and UX on Kindai Digital Lib. for Greasemonkey (not working yet) | |
// @include http://kindai.da.ndl.go.jp/* | |
// @include http://kindai.ndl.go.jp/* | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @version 2012.10.13.1 | |
// @homepage https://gist.github.com/3880159 | |
// @downloadURL https://raw.github.com/gist/3880159/kindai-util.user.js | |
// @installURL https://raw.github.com/gist/3880159/kindai-util.user.js | |
// @license Unknown (as-is) | |
// @contributor hitode909 https://gist.github.com/587659 | |
// @author noromanba (https://www.hatena.ne.jp/noromanba/) | |
// @icon https://upload.wikimedia.org/wikipedia/commons/6/6d/Fan%2C_Japanese.png | |
// @icon64 https://upload.wikimedia.org/wikipedia/commons/6/6d/Fan%2C_Japanese.png | |
// ==/UserScript== | |
// Icon (Public Domain) | |
// https://commons.wikimedia.org/wiki/File:Fan,_Japanese.png | |
// Devel | |
// https://gist.github.com/3880159 | |
// Script documents by hitode909 (written in Japanese) | |
// http://hitode909.hatenablog.com/entry/20100922/1285117233 | |
// http://hitode909.hatenablog.com/entry/20100923/1285223532 | |
// http://hitode909.hatenablog.com/entry/20101003/1286079150 | |
// Ruby gem "kindai" by hitode909 | |
// http://github.com/hitode909/kindairb | |
// https://rubygems.org/gems/kindai | |
// "Kindai Digital Library" (Digital Library from the Meiji Era) by National Diet Library | |
// http://kindai.ndl.go.jp/ | |
// 上のナビゲーションいらないので消す | |
(function() { | |
if (location.href.indexOf('info:ndljp/pid/') == -1) return; | |
var frame = document.querySelector('frameset'); | |
if (!frame) return; | |
frame.rows = '50, *'; | |
})(); | |
// 旧式ブラウザ対応viewにする | |
(function() { | |
if (location.href.indexOf('BIImgControl') == -1) return; | |
var menu = document.querySelector('#menu2'); | |
if (!menu || menu.value == 1) { | |
return; | |
} | |
menu.querySelector('option[value="1"]').selected = true; | |
unsafeWindow.imgDisp(0, 1); | |
// 印刷用URL | |
var downloadLink = document.querySelector('a[href="JavaScript:execDownload()"]'); | |
if (downloadLink) { | |
downloadLink.href = serializeForm({action: '/BIImgSelDisp.php'} , {}, document); | |
downloadLink.target = '_blank'; | |
} | |
})(); | |
// 前回のサイズ覚えておく | |
(function() { | |
if (location.href.indexOf('ndlimageviewer-rgc.aspx') == -1) return; | |
['dlImageSize', 'dlZoom'].forEach(function(key) { | |
// 変更時に記録 | |
document.querySelector('select#' + key).addEventListener('change', function(ev) { | |
// TODO omit GM | |
GM_setValue(key, this[this.selectedIndex].textContent); | |
}, false); | |
// selectされてるのが,前回とちがったら,戻す | |
try { | |
// TODO omit GM | |
var last = GM_getValue(key, ''); | |
var current = document.querySelector('select#' + key + ' option[selected]').textContent; | |
if (last != current) { | |
// TODO omit Array Generics | |
Array.forEach(document.querySelectorAll('select#' + key + ' option'), function(elem) { | |
if (elem.textContent == last) { | |
setTimeout(function() { | |
location.replace(elem.value); | |
}, 0); | |
} | |
}); | |
} | |
} catch(e) { | |
console.log(e); | |
} | |
}); | |
})(); | |
// 本文を見るリンク,新しいウィンドウ開かない | |
(function() { | |
if (location.href.indexOf('BIBibDetail.php') == -1) return; | |
var a = document.querySelector('img[src="./images/btn_honbun.gif"]').parentNode; | |
a.href = '/' + a.href.match(/'([^']+?)'\)/)[1]; | |
})(); | |
// 検索結果のリンクを普通のリンクにする | |
(function() { | |
if (location.href.indexOf('BIBibList.php') == -1) return; | |
// TODO omit Array Generics | |
Array.forEach(document.querySelectorAll('a[href^="JavaScript:submitDetail"]'), function(a) { | |
var id = a.href.match(/\('([^']+?)'/)[1]; | |
a.href = serializeForm({action: "./BIBibDetail.php"}, {tpl_select_row_no: id}, document); | |
}); | |
})(); | |
// 検索getにする | |
(function() { | |
var searchForm = document.querySelector('#searchArea form'); | |
if (!searchForm) return; | |
searchForm.method = 'get'; | |
})(); | |
// PDFダウンロードリンク | |
(function() { | |
if (location.href.indexOf('BIImgSelDisp.php') == -1) return; | |
var downloadLink = function(from, to) { | |
var a = document.createElement('a'); | |
a.textContent = from + '...' + to; | |
a.href = serializeForm({ action: './BIImgSelDispExec.php' }, { tpl_start_koma: from, tpl_end_koma: to }, document); | |
a.target = '_blank'; | |
return a; | |
}; | |
var title = document.createElement('h3'); | |
title.textContent = 'ページを指定してPDFを開く'; | |
document.body.appendChild(title); | |
var notice = document.createElement('p'); | |
var table = document.createElement('table'); | |
for(var i = 1; i < 500; i+=10) { | |
var tr = document.createElement('tr'); | |
for(var j = 9; j >= 0; j--) { | |
var td = document.createElement('td'); | |
var a = downloadLink(i, i + j); | |
td.appendChild(a); | |
tr.appendChild(td); | |
} | |
table.appendChild(tr); | |
} | |
document.body.appendChild(table); | |
})(); | |
// urlを返す | |
function serializeForm(form, merge, root) { | |
var params = { }; | |
if (!root) root = document; | |
// TODO omit Array Generics | |
Array.map(root.querySelectorAll('input'), function(input) { | |
params[input.name] = input.value; | |
}); | |
for(var key in merge) if (merge.hasOwnProperty(key)) { | |
params[key] = merge[key]; | |
} | |
var query = ''; | |
var pairs = []; | |
for(var key in params) if (params.hasOwnProperty(key)) { | |
pairs.push([key, params[key]]); | |
} | |
return form.action + '?' + pairs.map(function(_) { | |
return encodeURIComponent(_[0]) + '=' + encodeURIComponent(_[1]); | |
}).join('&'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment