PTT Long Change

Change on PTT.cc.

当前为 2018-05-27 提交的版本,查看 最新版本

// ==UserScript==
// @name        	PTT Long Change
// @description     Change on PTT.cc.
// @author         Lalong
// @include       	https://www.ptt.cc/bbs/*
// @include       	https://iamchucky.github.io/PttChrome/*
// @include       	https://www.ptt.cc/ask/over18*
// @version       	1.0.6
// @require         https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @namespace  https://greasyfork.org/zh-TW/scripts/33714-ptt-long-change
// @grant			 none
// ==/UserScript==


$(document).ready(function(){

  //加CSS
     if ($('#delayCss').length == 0) {
         var css=' .topbar{background-color:rgba(0, 0, 136, 0.4);opacity: 0;transition: opacity 0.3s;} ';
         css+=' .topbar:hover{background-color:rgba(10, 106, 196, 0.4);opacity:1;} ';
            var head = document.getElementsByTagName('head')[0];
            var style = document.createElement('style');
            style.type = 'text/css';
            style.id = 'delayCss';
            if (style.styleSheet) {
                style.styleSheet.cssText = css;
            } else {
                style.appendChild(document.createTextNode(css));
            }
            head.appendChild(style);
        }
        else {
            $('delayCss').html(css);
        }

    var temp =$('.btn-big');
    if( temp.length  > 0){temp[0].click();}
    //if(document.body.scrollTop>38.5)

    $('body').css('background-color','black');
    $('#topbar-container').addClass('topbar');
    $('#navigation-container').remove();
    $('.right').remove();


    var poName =$('.article-meta-value').eq(0).text().split(' ')[0];

	var pushes = document.querySelectorAll(".push"),
		i;

	function createCount(i, base) {
		var span = document.createElement("span");
		span.className = "push-count push-tag";
        span.style="color:grey;";
        if(pushes.length >= 100){
            if(i<100){span.textContent = "  "+i+"樓 ";}
            if(i<10){span.textContent = "    "+i+"樓 ";}
            if(i>=100){span.textContent = i+"樓 ";}
        }
        else{
            if(i<10){span.textContent = "  "+i+"樓 ";}
            else {span.textContent = i+"樓 ";}
        }
		return span;
	}

	for (i = 0; i < pushes.length; i++) {
		pushes[i].insertBefore(createCount(i + 1, pushes[i]), pushes[i].children[0]);
        //var id=document.getElementsByClassName('f3 hl push-userid')[i].innerText.trim();
        var id=$('div.push').children('.push-userid').eq(i).text().trim();

        if(id == poName){
            //document.getElementsByClassName('f3 hl push-userid')[i].setAttribute('style','background-color:rgb(0,70,0);');
            $('div.push').children('.push-userid').eq(i).css('background-color','rgb(0,70,0)');
        }
        //document.getElementsByClassName('f3 hl push-userid')[i].setAttribute('id',id);
        $('div.push').children('.push-userid').eq(i).attr('id',id);
        document.getElementsByClassName('f3 hl push-userid')[i].setAttribute('onclick','go(\'#\' + this.id);');
	}

    var script = document.createElement('script');
script.appendChild(document.createTextNode(go +';'));
(document.body || document.head || document.documentElement).appendChild(script);

 function go(x){
     //console.log(this);
     var metatext=document.getElementsByClassName('article-meta-value')[0].innerText;
     var name = metatext.split(" ",2)[1];

     var all = document.querySelectorAll('.push');
     var elements = document.querySelectorAll(x);
     for(var j=0; j<all.length; j++){
         if(all[j].children[2].id == name){
             if(elements[0].id != name){all[j].children[2].removeAttribute('name');}
             all[j].children[2].style.backgroundColor = 'rgb(0,70,0)';}
         else{
             if(elements[0].id != all[j].children[2].id){
                 all[j].children[2].removeAttribute('style');}
         }
         //all[j].children[2].removeAttribute('name');
     }


     for(var i=0; i<elements.length; i++) {
         if( elements[i].getAttribute('style') !== null){
             if(elements[i].id==name){
                 if( elements[i].getAttribute('name') === null){
                      elements[i].style.backgroundColor='rgb(0,0,90)';
                      elements[i].setAttribute('name','pri');
                 }
                 else{
                     elements[i].style.backgroundColor='rgb(0,70,0)';
                     elements[i].removeAttribute('name');}
                 }
             else{
                 elements[i].removeAttribute('style');}
         }
         else{
             elements[i].style.backgroundColor='rgb(0,0,90)';}
     }
 }

})();