/*
* @title copylet
* @description show minified code on Hatena::Let; for copy of mobile
* @include http://let.hatelabo.jp/*
* @include http://let.st-hatelabo.com/*
* @contributor mino90 http://let.hatelabo.ne.jp/mino90/let/gYC-xYDKx6O-dA
* @contributor noromanba http://let.hatelabo.jp/noromanba/let/hLHUzoSn6YtX (Fork of)
* @license MIT License http://opensource.org/licenses/MIT
* @javascript_url
*/
// WIP
// - [x] only once execute
// - [ ] @javascript_url-nize both of loader-code
// - TODO support @require e.g.
// http://let.hatelabo.jp/mattn/let/gYC-ypuU7rrgaQ
// Hatena::Let loader's bug; missing semicolons of loader
// - self patching? WTH
// completely copy, but needs twice execute ver.
// http://let.hatelabo.jp/noromanba/let/hJmczoeEkbdW
(() => {
if (!/let\.(?:st\-)?hatelabo\.(?:jp|com)$/.test(location.hostname) ||
location.pathname.split('/').slice(1) < 3) {
return;
}
const packed = document.body.querySelector('.information a[href$="packed.js"]');
const xhr = new XMLHttpRequest();
xhr.open('GET', packed.href);
xhr.timeout = 2000;
xhr.addEventListener('load', () => {
if (xhr.readyState !== 4 || xhr.status !== 200) return;
// TBD readonly textarea
const input = document.createElement('input');
input.style.position = 'absolute';
input.style.top = '0';
input.style.left = '0';
input.style.width = '50%';
input.type = 'text';
//*/
input.value = 'javascript:' + xhr.responseText;
/*/
// same as orig, but obsolete
input.value = 'javascript:' + escape(xhr.responseText);
// recommended
input.value = 'javascript:' + encodeURIComponent(xhr.responseText);
//*/
document.body.appendChild(input);
input.select();
input.scrollIntoView();
});
xhr.send();
})();