Improve logsoku & 2ch for PC and Smartphone

display image directly, add links that show a certain accout of floor

当前为 2014-09-05 提交的版本,查看 最新版本

// ==UserScript==
// @name           Improve logsoku & 2ch for PC and Smartphone
// @description    display image directly, add links that show a certain accout of floor
// @include        http://www.logsoku.com/*
// @include        http://sp.logsoku.com/*
// @author         yechenyin
// @version        0.29
// @namespace 	   https://gf.qytechs.cn/scripts/3497
// ==/UserScript==


/**************************以下参数可自定义修改**************************/

//图片显示默认缩放比例
var percent = 0.5;

//图片显示最大高度(像素)
var image_max_height = 420;

//图片显示最大宽度(像素)
var image_max_width = 600;

//图片显示最小高度(像素)
var image_min_height = 240;

//显示显示最小宽度(像素)
var image_min_width = 320;

//弹出图片的原图,要取消此功能请将true改为false
var popup_enable = true;

//点击图片后隐藏图片,要取消此功能请将true改为false
var click_to_hide_image = true;


//
var phone_searched_links_contain_comments = 200;

//
var contain_floores = 250;

//
var pc_searched_links_contain_comments = 500;

//
var latest_floors = 150;


/****************************************************/

if (location.href.match("http://sp.logsoku.com/search")) {
    $("a.search_thread_title").each(function() {
	last_comment = $(this).next().find(".res span").text().replace(" ", "");
	var all_comments = $("<a>", {href:this.href + "1-" + last_comment});
	$(this).next().find(".res span").wrap(all_comments);
	
	this.href += "l" + phone_searched_links_contain_comments;
	var time = $(this).next().find(".date").text();
	time = time.replace(/\d{4}-/, "").replace(/:\d{2}\s/, " ");
	time = time.replace(/\d{4}-/, "").replace(/:\d{2}\s$/, " ");
	$(this).next().find(".date").text(time);
    });
}


if (location.href.match("http://sp.logsoku.com/r/")) {
    
    var filter_menu = $("<li>", {class:"dropdown open filter"});
    var innerHTML = "<a href='#' class='dropdown-toggle'>过滤<b class='caret'></b></a>";
    innerHTML += "<ul class='dropdown-menu filter-menu' style='display:none'>";
    innerHTML += "<li id='all_comments'><a>全部</a></li><li class='divider'></li>";
    innerHTML += "<li id='all_comments_hide_images'><a>不显示图片</a></li><li class='divider'></li>";
    innerHTML += "<li id='only_reply_and_links'><a>只含回复及链接</a></li><li class='divider'></li>";
    innerHTML += "<li id='only_links_and_images'><a>只含链接及图片</a></li><li class='divider'></li>";
    innerHTML += "<li id='only_images'><a>只含图片</a></li> </ul>";
    filter_menu.html(innerHTML);
    filter_menu.insertBefore($("ul.nav>li:last-child").eq(0));
    var filter_clicked = function (filter) {
	localStorage.filter = filter;
	filter_comments();
    }
    
    $("li.filter>a").click(function() {
	$(this).next().toggle();
    });
    
    
    $("ul.filter-menu").on("click", "li", filter_comments);
    
    
    $("dt br").remove();
    $("dt .nem, dt>b").remove();
    $("dt").append($("<span>", {text:"block this ID", click:blockId}));
    //$("dt").append($("<span>", {text:"block images blow", click:blockImages}));
    $("dt").each(function() {
	var id = $(this).find("a[class^='id']").text();
	if (localStorage.blacklist_ids.indexOf(id)>0) {
	    $(this).next().hide();
	    $(this).hide();
	}
    });

    $("dd>a").each(function() {
	if (this.href.match("http://l.moapi.net/")) {
	    this.href = this.href.replace("http://l.moapi.net/", "");
	    
	    if (this.href.match(/.\.(jpg|jpeg|gif|png)$/) && localStorage.filter != "all_comments_hide_images") 
		$(this).replaceWith($("<img>", {src: this.href}));
	} 
    });
    
    if (localStorage.filter == "only_reply_and_links") {
	$("dd[id^=comment]").each(function() {
	    if ($(this).find("a, img").length === 0) {
		$(this).prev().hide();
		$(this).hide();
	    }
	});
    } else if (localStorage.filter == "only_links_and_images") {
	$("dd[id^=comment]").each(function() {
	    if ($(this).find("a[href^='http:'], img").length === 0) {
		$(this).prev().hide();
		$(this).hide();
	    }
	});
	
    } else if (localStorage.filter == "only_images") {
	$("dd[id^=comment]").each(function() {
	    if ($(this).find("img").length === 0) {
		$(this).prev().hide();
		$(this).hide();
	    }
	});
    }
    
    
}

function blockId() {
    if (localStorage.blacklist_ids == undefined) 
	localStorage.blacklist_ids = "";
    var id = $(this).parent().find("a[class^='id']").text();
    localStorage.blacklist_ids += id + ",";
    
    $(this).parent().next().hide();
    $(this).parent().hide();
}

function filter_comments() {
    if (this.nodeName == "li" && this.id !== undefined) 
	    localStorage.filter = this.id;
	
    $("ul.filter-menu>li").each(function() {
	if (this.id == localStorage.filter) 
	    $(this).css("background", "#d8edff");
	else
	    $(this).css("background", "#fff");
    });
    $("ul.filter-menu").hide();
    
    if (localStorage.filter == "all_comments") {
	$("dd[id^=comment]").each(function() {
	    $(this).prev().show();
	    $(this).show();
	});
    } else if (localStorage.filter == "only_reply_and_links") {
	$("dd[id^=comment]").each(function() {
	    if ($(this).find("a, img").length === 0) {
		$(this).prev().hide();
		$(this).hide();
	    } else {
		$(this).prev().show();
		$(this).show();
	    }
	});
    } else if (localStorage.filter == "only_links_and_images") {
	$("dd[id^=comment]").each(function() {
	    if ($(this).find("a[href^='http:'], img").length === 0) {
		$(this).prev().hide();
		$(this).hide();
	    } else {
		$(this).prev().show();
		$(this).show();
	    }
	});
	
    } else if (localStorage.filter == "only_images") {
	$("dd[id^=comment]").each(function() {
	    if ($(this).find("img").length === 0) {
		$(this).prev().hide();
		$(this).hide();
	    } else {
		$(this).prev().show();
		$(this).show();
	    }
	});
    }
    
}

function pc_filter_comments() {
    if (this.nodeName !== undefined && this.id !== undefined) 
	    localStorage.filter = this.id;
	
    $("ul.filter-menu>li").each(function() {
	if (this.id == localStorage.filter) 
	    this.css("background", "#d8edff");
	else
	    this.css("background", "#fff");
    });
    $("ul.filter-menu").hide();
    
    if (localStorage.filter == "all_comments") {
	$("dd[id^=comment]").each(function() {
	    $(this).prev().show();
	    $(this).show();
	});
    } else if (localStorage.filter == "only_reply_and_links") {
	$("dd[id^=comment]").each(function() {
	    if ($(this).find("a, img").length === 0) {
		$(this).prev().hide();
		$(this).hide();
	    } else {
		$(this).prev().show();
		$(this).show();
	    }
	});
    } else if (localStorage.filter == "only_links_and_images") {
	$("dd[id^=comment]").each(function() {
	    if ($(this).find("a[href^='http:'], img").length === 0) {
		$(this).prev().hide();
		$(this).hide();
	    } else {
		$(this).prev().show();
		$(this).show();
	    }
	});
	
    } else if (localStorage.filter == "only_images") {
	$("dd[id^=comment]").each(function() {
	    if ($(this).find("img").length === 0) {
		$(this).prev().hide();
		$(this).hide();
	    } else {
		$(this).prev().show();
		$(this).show();
	    }
	});
    }
    
}

if (location.href.match("http://www.logsoku.com/search")) {
    var results = document.getElementById("search_result_threads");
    if (results) {
    var titles = results.getElementsByClassName("title");
    
    for (i=0; i<titles.length; i++) {
	var link = titles[i].children[0];
	if (link)
	    link.href = link.href + "l" + search_result_latest_floors;
    }
    }
}


if (location.href.match("http://www.logsoku.com/r/")) {
	$("div.comment").each(function() {
	    if ($(this).find("a[href^='http://l.moapi.net/'], img").length === 0) 
		$(this).parent().hide();
	     else 
		$(this).parent().show();
	});
	
    var links = document.links;
    for (j=0; j<links.length; j++) {
	links[j].href = links[j].href.replace("http://l.moapi.net/", "");
	
	if (links[j].innerHTML.match(/.\.(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG)$/)) {
	    var img = document.createElement("img");
	    if (links[j].innerHTML.match(/\w*:?\/\//)) 
		img.src = links[j].innerHTML.replace(/\w*:?\/\//, "http://");
	    else
		img.src = "http://" + links[j].innerHTML;
		
	    img.style.display = "none";
	    img.onload = resize;
	    if (click_to_hide_image)
		img.onclick = function() { this.style.display = "none"};
	    if (popup_enable) {
		var container = document.createElement("div");
		container.style.display = "inline";
		container.onmouseover = function() { this.children[0].style.display = "inline"};
		container.onmouseout  = function() { this.children[0].style.display = "none"};
		container.appendChild(img);
	    }
	    links[j].parentNode.replaceChild(container, links[j]);
	    j--;
	} 
	
    }
    //pc_filter_comments();


//    var filter_menu = $("<li>", {class:"dropdown open filter"});
//    var innerHTML = "<a href='#' class='dropdown-toggle'>过滤<b class='caret'></b></a>";
//    innerHTML += "<ul class='dropdown-menu filter-menu' style='display:none'>";
//    innerHTML += "<li id='all_comments'><a>全部</a></li><li class='divider'></li>";
//    innerHTML += "<li id='all_comments_hide_images'><a>不显示图片</a></li><li class='divider'></li>";
//    innerHTML += "<li id='only_reply_and_links'><a>只含回复及链接</a></li><li class='divider'></li>";
//    innerHTML += "<li id='only_links_and_images'><a>只含链接及图片</a></li><li class='divider'></li>";
//    innerHTML += "<li id='only_images'><a>只含图片</a></li> </ul>";
//    filter_menu.html(innerHTML);
//    filter_menu.insertBefore($("ul.nav>li:last-child"));
//    var filter_clicked = function (filter) {
//	localStorage.filter = filter;
//	filter_comments();
//    }
//    
//    $("li.filter>a").click(function() {
//	$(this).next().toggle();
//    });
//    
//    
//    $("ul.filter-menu").on("click", "li", filter_comments);
    
    var nav = document.getElementsByClassName("thread-nav")[0].children[0];
    if (nav) {
    var base = nav.children[2].href;
    nav.children[3].href = base + "l" + latest_floors;
    
    for (i=0; i<1000/contain_floores; i++) {
	var link = document.createElement("a");
	var range = String(i*contain_floores+1) + "-" +  String((i+1)*contain_floores);
	link.href= base + range;
	link.innerHTML = range;
	link.className = "nav-btn";
	nav.appendChild(link);
    }
    }
    
    
    
    
    var hide_name = true;
    if (hide_name) {
	var names = document.querySelectorAll("span.nem, span.em");
	for (i=0; i<names.length; i++) {
	    names[i].style.display = "none";
	    names[i].nextSibling.replaceData(0, 3, "");
	    colon_pos = names[i].previousSibling.text.indexOf(":");
	    names[i].previousSibling.replaceData(colon_pos+1, 1, "");
	}
    }
    
    var comments = document.getElementsByClassName("comment");
    for (i=0; i<comments.length; i++) {
	var id = comments[i].previousSibling.previousSibling.text;
	if (localStorage.blacklist_ids.search(id) >= 0) {
	    comments[i].parentNode.style.display = "none";
	}
	console.log(localStorage.blacklist_ids);
	
	
	var hide_id = document.createElement("span");
	hide_id.innerHTML = "&nbsp;(block this ID'comemnts)";
	hide_id.style.color = "#666";
	hide_id.style.cursor = "pointer"
	hide_id.onclick = function () {
	    localStorage.blacklist_ids += id + " ";
	    this.parentNode.style.display = "none";
	};
	comments[i].parentNode.insertBefore(hide_id, comments[i]);
    }
    
    
    var search_box = document.getElementsByClassName("top-search-box").parentNode;
    var black_list = document.createElement("li");
    var black_list_link = document.createElement("a");
    black_list_link.onclick = function () {
	    this.previousSibling.style.display = "inline";
	};
    var black_list_text = document.createElement("span");
    black_list_text.innerHTML = "black list";
    black_list_link.appendChild(black_list_text);
    search_box.appendChild(black_list_link);
    
    
    // draw black list configuration board
    var black_list_configuration = document.createElement("div");
    black_list_configuration.style.textAlign = "center";
    var close = document.createElement("a");
    close.innerHTML = "&#10006;&times;";
    close.style.cssText = "float:right; padding:3px; border:1px #666 solid";
    close.onclick = function () {
	    this.parentNode.style.display = "inline";
	};
    black_list_configuration.appendChild(close);
    
    var text = document.createElement("span");
    text.innerHTML = "IDs in the black list(seperate by space):";
    black_list_configuration.appendChild(text);
    var textarea = document.createElement("textarea");
    textarea.innerHTML = localStorage.blacklist_ids;
    textarea.id = "blacklist_ids";
    black_list_configuration.appendChild(textarea);
    
    var text = document.createElement("span");
    text.innerHTML = "Contents in the black list(seperate by new line):";
    black_list_configuration.appendChild(text);
    var textarea = document.createElement("textarea");
    textarea.innerHTML = localStorage.blacklist_contents;
    textarea.id = "blacklist_contents";
    black_list_configuration.appendChild(textarea);
    
    var close = document.createElement("a");
    close.innerHTML = "save";
    close.style.cssText = "padding:3px; border:1px #666 solid";
    close.onclick = function () {
	var input = document.getElementById("blacklist_ids");
	localStorage.blacklist_ids = input.nodeValue;
	var input = document.getElementById("blacklist_contents");
	localStorage.blacklist_contents = input.nodeValue;
	this.parentNode.style.display = "none";
	};
    black_list_configuration.appendChild(close);

}

function resize() {
    var w = this.naturalWidth;
    var h = this.naturalHeight;
    var width = this.naturalWidth * percent;
    var height = this.naturalHeight * percent;
    
    height = height > image_max_height ? image_max_height : height;
    height = height < image_min_height ? image_min_height : height;
    width = height * w/h;
    
    
    width = width > image_max_width ? image_max_width : width;
    width = width < image_min_width ? image_min_width : width;
    height = width * h/w;
    
    height = height > image_max_height ? image_max_height : height;
    height = height < image_min_height ? image_min_height : height;
    width = height * w/h;
    
    this.width = width;
    this.height = height;
    this.style.display = "block"
    
    
    //insert popup image
    if (popup_enable) {
	var popup_img = document.createElement("img");
	var width = w;
	var height = h;
	var clientWidth = document.body.clientWidth;
	var clientHeight = document.body.clientHeight;
	
	
	if (height > clientHeight) {
	    heigth = clientHeight;
	    width = clientHeight * w/h;
	}
	if (width > clientWidth) {
	    width = clientWidth;
	    height = clientWidth * h/w;
	    
	    if (height > clientHeight) {
		heigth = clientHeight;
		width = clientHeight * w/h;
	    }
	} 
	popup_img.heigth = height;
	popup_img.width = width;
	
	popup_img.src = this.src;
	popup_img.style.zIndex = 2;
	popup_img.style.position = "fixed";
	popup_img.style.left = "0px";
	popup_img.style.top = "0px";
	popup_img.style.display = "none";
	//popup_img.onmouseout = function() { this.style.display = "none"};
	//var download = document.createElement("a");
	//download.setAttribute("download", "");
	//download.appendChild(popup_img);
	this.parentNode.insertBefore(popup_img, this);
	this.parentNode.heigth = height;
	this.parentNode.width = width;
	}
    
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址