リトルノア ファミ通coop掲示板 リロード bookmarklet

  • /*
     * @title リトルノア ファミ通coop掲示板 リロード bookmarklet
     * @description リトルノアのファミ通Wikiにあるcoop掲示板をリロードしやすくします。元 source は github ( https://github.com/limura/littlenoah_coop_bookmarklet ) で書いています。
     * @license MIT License
     * @include http://wiki.famitsu.com/littlenoah/*
     */
    
    (function(){
    	prevTextList = [];
    	timeoutID = null;
    	loadCSS = function(url){
    		$('head link:last').after('<link rel="stylesheet" href="' + url + '">');
    	};
    	loadJavaScript = function(url){
    		$('head link:last').after('<script href="' + url + '">');
    	};
    	cdn = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/";
    	loadCSS(cdn+"css/bootstrap.min.css");
    	loadJavaScript(cdn+"js/bootstrap.min.js");
    	statusLoading = function(text){
    		$("#status").html(text);
    		$("#status").show();
    		$("#reloadButton").attr('disabled', true);
    	}
    	statusWaiting = function(){
    		$("#status").hide();
    		$("#reloadButton").removeAttr('disabled');
    	}
    	load = function(s){
    		$.ajax({url: window.location.href, type: "GET", success: s, error: function(err){
    			statusLoading("load error. " + err);
    			$("#reloadButton").removeAttr('disabled');
    		}});
    	}
    	reloadCount = 30;
    	render=function(postList){
    		html = '<div class="col-md-12">'
    		+ postList.join('')
    		+ '<div class="text-right"><a id="reloadButton" onClick="reload();" class="btn btn-primary" href="#">reload</a>&nbsp;&nbsp;&nbsp;</div><div id="status"></div></div>';
    		$('body').html(html);
    		statusWaiting();
    	}
    	reloadFunc = function(data){
    		if(timeoutID != null){
    			clearTimeout(timeoutID);
    		}
    		statusLoading("Now Loading..." + reloadCount);
    		contents = $(data).find('.content');
    		newPostList = [];
    		newTextList = [];
    		isNewAlive = false;
    		for(var i = contents.length - 1; i >= 0; i--){
    			c = contents.eq(i);
    			text = c.find('.comment-body').text();
    			newTextList.push(text);
    			post = '<div class="col-md-12">'
    			+ text;
    			if(prevTextList.indexOf(text)<0){
    				post += ' <span style="color:red">New!</span>';
    				isNewAlive = true;
    			}
    			post += '</div><div style="font-size:xx-small" class="col-md-12">'
    			+ c.find('.comment-create-date').text()
    			+ "</div>";
    			newPostList.push(post);
    		}
    		prevTextList = newTextList;
    		render(newPostList);
    		if(!isNewAlive){
    			reloadCount--;
    			if(reloadCount <= 0){
    				statusLoading('<span style="color:orange">reload stoped.</span> ' + reloadCount);
    				$("#reloadButton").removeAttr('disabled');
    				return;
    			}
    			statusLoading("Now loading..." + reloadCount);
    			console.log("reloading...");
    			timeoutID = setTimeout(function(){load(reloadFunc);}, 800);
    		}else{
    			reloadCount = 30;
    		}
    	};
    	reload=function(){
    		reloadCount = 30;
    		statusLoading("Now Loading..." + reloadCount);
    		load(reloadFunc);
    	}
    	reload();
    })();
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2015/04/09 11:05:54 - 2015-04-09
  2. 2015/04/09 11:01:22 - 2015-04-09
  3. 2015/04/06 15:08:01 - 2015-04-06
  4. 2015/04/06 15:05:57 - 2015-04-06
  5. 2015/04/05 18:21:56 - 2015-04-05
  6. 2015/04/05 16:36:18 - 2015-04-05
  7. 2015/04/04 19:33:11 - 2015-04-04
  8. 2015/04/04 18:46:45 - 2015-04-04
  9. 2015/04/04 18:26:28 - 2015-04-04