Skip to content

Instantly share code, notes, and snippets.

@satyr
Created March 12, 2009 23:49
Show Gist options
  • Save satyr/78362 to your computer and use it in GitHub Desktop.
Save satyr/78362 to your computer and use it in GitHub Desktop.
XML.prettyPrinting = XML.ignoreWhitespace = false;
const
Name = 'bijin-tokei',
BT = 'http://www.bijint.com',
Base = [<div class={Name +' root'}
><div class="acts"
><input type="button" id="copy" accesskey="c" disabled="disabled" value="Copy"
/><input type="button" id="open" accesskey="o" disabled="disabled" value="Open"
/></div
><div id={Name} class="content"> </div
><a class="logo" accesskey="l" href={BT}
><img src={BT +'/img/logo.jpg'}/></a
></div>],
HTML = '<style>'+ <![CDATA[
input {padding:0; border-width:1px; font:bold 92% monospace}
img {border:none; max-width:100%}
.root {position:relative}
.acts {position:absolute; top:0; right:0}
.content {text-align:center}
.info {padding:0.3em}
.logo > img {vertical-align:middle}
]]> +'</style>'+ Base,
Acts = {
src: null,
copy: function(){ CmdUtils.copyToClipboard(this.src) },
open: function(){ Utils.openUrlInBrowser(this.src) },
insert: function()
this.src && (
CmdUtils.setSelection('<img src="'+ Utils.escapeHtml(this.src) +'"/>',
{text: this.src}),
true),
};
function clock(time, fun){
$.ajax({
url: BT +'/cache/'+ time.toString('HHmm') +'.html',
dataType: 'text',
beforeSend: ref,
success: function bt_success(htm){
var src = Acts.src = BT +'/jp/'+ (/\bsrc="(.+?)"/.exec(htm) || 0)[1]
$.ajax({_ref: this.url, url: src, beforeSend: ref})
fun(src,
$(htm.replace(/<img [^>]+>|<script [^]+/g, ''))
.find('.f12-8, .f15').slice(0, 7).map(tpluck).get())
},
})
}
function ref(xhr){ xhr.setRequestHeader('Referer', this._ref || BT +'/jp/') }
function tpluck() this.textContent;
function onclick(e){
var b = e.target;
if(b.type !== 'button') return;
e.preventDefault();
b.blur();
b.disabled = true;
Acts[b.id]();
}
CmdUtils.CreateCommand({
name: Name,
icon: BT +'/img/favicon.ico',
description: '\u7F8E\u4EBA\u6642\u8A08'.link(BT),
help:
'<ul style="list-style-image:none">'+
[<li><code><kbd>{b.@accesskey}</kbd></code>
: {b.@title +'' || b +''}</li>
for each(b in Base[0]..button)].join('') +
'<li>Execute to insert the image.</li></ul>',
argument: {object_when: noun_type_time},
execute: function bt_execute({object: {data}}){
Acts.insert() || clock(data, function(){ Acts.insert() });
},
preview: function bt_preview(pb, {object: {text, data}}){
var cn, doc = pb.ownerDocument;
while(!(cn = doc.getElementById(Name))){
pb.innerHTML = HTML;
doc.querySelector('.acts').addEventListener('click', onclick, false);
}
clock(data, function bt_set(src, info){
cn.innerHTML =
<><a class="tokei" href={src}><img src={src} alt={text} title={text}
/></a><div class="info">{info.join(' | ')}</div></>
$('input', pb).attr('disabled', false)
})
},
})
const BG = 'http://www.bijogoyomi.com/'
CmdUtils.CreateCommand({
name: 'bijogoyomi',
description: '\u7F8E\u5973\u66A6'.link(BG),
execute: BG +'bijo/?linkid=from_pctop',
preview: function bg_preview(pb){
if(pb.ownerDocument.getElementById('bijogoyomi')) return;
pb.innerHTML = <div id="bijogoyomi"><a href={BG} accesskey="/">
<span class="frame"><dummy/></span
><img src={BG +'news/wp-content/themes/bijo/images/bijo_logo.gif'}
style="border:none;vertical-align:bottom"/>
</a></div>
CmdUtils.previewGet(
pb, 'http://www.bijogoyomi.com/bijo/today.php?u=NHiCnoKJ-MJQuOHbN', 0,
function(xml){
(pb.querySelector('.frame') || 0).innerHTML =
'<img border=0 align=absbottom src'+ /="http.+?"/.exec(xml) + '/>'
}, 'text')
},
})
$.extend(feed, {author: 'satyr', license: 'X'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment