Skip to content

Instantly share code, notes, and snippets.

@basyura
Created Aug 4, 2010
Embed
What would you like to do?
// ==UserScript==
// @name ldr-view-progress
// @namespace http://basyura.org
// @include http://reader.livedoor.com/reader/
// ==/UserScript==
//
(function(){
const ONE_HOUR = 60 * 60 * 1000;
const ONE_MINUTE = 60 * 1000;
const PROGRESS_HEIGHT = '40px';
const PROGRESS_FONTSIZE_SMALL = '10px';
const PROGRESS_FONTSIZE_MIDDLE = '20px';
const PROGRESS_FONTSIZE_LARGE = '30px';
const SPELL = '臨兵闘者皆陣列在前';
const TIMER = 5000;
const MAX = 2 * ONE_HOUR;
let progress_ = null;
let spell_index_ = 0;
/*
* MAX に対する period の分だけプログレスバーを伸ばす
*/
function expand_progress(period) {
if(progress_ == null) {
progress_ = document.createElement('div');
progress_.style.paddingLeft = '5px';
progress_.style.border = '3px double #ffffff';
progress_.style.color = '#ffffff';
progress_.style.height = PROGRESS_HEIGHT;
progress_.style.position = 'absolute';
progress_.style.top = 0;
document.body.appendChild(progress_);
}
// 表示するパーセンテージを算出
let percent = (period / MAX) * 100;
// パーセンテージによって色を変える
if(percent < 40) {
progress_.style.fontSize = PROGRESS_FONTSIZE_SMALL;
progress_.style.backgroundColor = '#6d9bff';
}
else if(percent < 60) {
progress_.style.fontSize = PROGRESS_FONTSIZE_MIDDLE;
progress_.style.backgroundColor = 'orange';
}
else if(percent < 90) {
progress_.style.fontSize = PROGRESS_FONTSIZE_LARGE;
progress_.style.backgroundColor = 'magenta';
}
else {
progress_.style.fontSize = PROGRESS_FONTSIZE_LARGE;
progress_.style.backgroundColor = 'red';
appendNoise(countUpSpellCount());
}
// スタイル変更で伸ばす
progress_.style.width = percent.toString() + '%';
// 経過時間を算出
let hour = parseInt(period / ONE_HOUR , 10);
let min = parseInt((period - hour * ONE_HOUR) / ONE_MINUTE , 10);
let sec = parseInt((period - hour * ONE_HOUR - min * ONE_MINUTE) / 1000 , 10);
// 経過時間表示。1時間に満たない場合は分だけ表示
let msg = hour != 0 ? (hour + "h ") : "";
msg += min + "m " + sec + "s";
// メッセージ表示
progress_.textContent = msg;
}
/*
* 臨兵闘者皆陣列在前
*/
function appendNoise(i) {
var noise = document.createElement('b');
noise.className = 'noise';
noise.textContent = SPELL.charAt(spell_index_++);
if (SPELL.length <= spell_index_) spell_index_ = 0;
with(noise.style) {
zIndex = 1000000;
fontSize = (i % 60) + 'px';
position = 'absolute';
opacity = 1 - (i % 10) * 0.1;
left = (Math.random() * 140 - 20) + '%';
top = (Math.random() * 140 - 20) + '%';
cursor = 'pointer';
}
document.body.appendChild(noise);
}
/*
* 起動時にプログレスバーを伸ばす
*/
function progress_startup(timer_period) {
let period = GM_getValue('view_progress_period');
let timer_period = timer_period + (period / 10);
expand_progress(timer_period);
if(timer_period < period) {
setTimeout(function(){progress_startup(timer_period)} , 100);
}
}
/**
*
*/
function countUpSpellCount() {
let count = GM_getValue('view_progress_spell_count') + 1;
GM_setValue('view_progress_spell_count' , count);
return count;
}
/*
*
*/
function getSpellCount() {
let count = GM_getValue('view_progress_spell_count')
return count == null ? 0 : count;
}
/*
* 初期処理
* 日付が変わった場合は初期化する
*/
function setUp() {
GM_registerMenuCommand('ldr view progress - reset', function() {
GM_setValue('view_progress_period' , 0);
GM_setValue('view_progress_spell_count' , 0);
});
let date = GM_getValue("view_progress_date");
let now = new Date();
let today = [now.getFullYear(), now.getMonth() + 1, now.getDate()].join('-');
if(date != today) {
alert("reset");
GM_setValue("view_progress_date" , today);
GM_setValue('view_progress_period' , 0);
GM_setValue('view_progress_spell_count' , 0);
}
// プログレスバー初期描画
progress_startup(0);
// ノイズ描画
for(let i = 0 ; i < getSpellCount() ; i++) {
appendNoise(i);
}
// タイマー
setInterval(function(){
let period = GM_getValue('view_progress_period') + TIMER;
expand_progress(period);
GM_setValue('view_progress_period' , period);
} , TIMER);
}
setUp();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment