Fix Comment Preview box on crikey blogs
当前为
// ==UserScript==
// @name CrikeyCleanCommentPreview
// @author Musrum
// @namespace 2
// @description Fix Comment Preview box on crikey blogs
// @include http://blogs.crikey.com.au/*
// @include http://www.crikey.com.au/*
// @exclude http://www.crikey.com.au/*.gif
// @require https://greasyfork.org/scripts/1884-gm-config/code/GM_config.js?version=4836
// @grant none
// @version 5.01
// ==/UserScript==
// Ver 5.00
// New major version to deal with New, souped-up Crikey
// Ver 5.01
// Added Recommend CCCP
var scriptVer = '5.01';
////////////////////////////////////////////////////////////////////////////////
/*jslint browser: true */
/*global GM_config, GM_registerMenuCommand */
////////////////////////////////////////////////////////////////////////////////
//don't run in iframes
if (window.top !== window.self) {
return;
}
////////////////////////////////////////////////////////////////////////////////
// URLS
var ff = ["Firefox" ,"http://www.mozilla.com/en-US/firefox/personal.html"];
var gm = ["Greasemonkey" ,"https://addons.mozilla.org/en-US/firefox/addon/748"];
var gc = ["Google Chrome","http://www.google.com/chrome"];
var tm = ["Tampermonkey" ,"https://chrome.google.com/webstore/detail/dhdgffkkebhmkfjojejmpbldmpobfkfo"];
var cc = ["cccp" ,"https://greasyfork.org/en/scripts/18677-crikeycleancommentpreview"];
////////////////////////////////////////////////////////////////////////////////
// Onload ...
window.addEventListener('load', function () {
// if ( ! document.getElementById("menu-item-543649") && window.location.href.match(/www.crikey.com.au/) ) {
// autoLogin();
// } else {
main();
// }
});
////////////////////////////////////////////////////////////////////////////////
// Config settings dialog
GM_config.storage = 'Crikey Clean Comment Preview';
GM_config.init('Crikey Clean Comment Preview - Ver ' + scriptVer,
{
cleanVertSpace: {
label: 'Clean Vertical Space',
type: 'checkbox',
'default': false
}
},
{
open: function() {
GM_config.addBorder(); // add a fancy border
GM_config.resizeFrame('200px','300px'); // resize the config window
}
},
{
save: function () { location.reload(); } // reload the page when configuration was changed
}
);
////////////////////////////////////////////////////////////////////////////////
function showConfigCCCP() {
GM_config.open();
}
////////////////////////////////////////////////////////////////////////////////
function autoLogin() {
document.getElementById("choice_7_3_1").checked = true;
var pw = document.getElementById("input_7_2");
pw.value = 'foo';
document.getElementById("gform_submit_button_7").click();
}
////////////////////////////////////////////////////////////////////////////////
// If we are logged in, perform additional steps related to commenting
function main() {
if ( document.getElementById("menu-item-543649") ) {
mainFormating();
mainCommenting();
} else {
mainFormating();
}
}
////////////////////////////////////////////////////////////////////////////////
function mainFormating() {
console.log('mainFormating()');
cleanVerticalSapce();
nicerCommentNavigation();
cccpNavBar();
}
////////////////////////////////////////////////////////////////////////////////
// Clean out wasted vertical space
function cleanVerticalSapce() {
if (GM_config.get('cleanVertSpace') !== true) {return;}
document.getElementsByClassName("article-body__share")[0].style.display = 'none';
document.getElementsByClassName("author ")[0].style.display = 'none';
document.getElementsByClassName("author ")[1].style.display = 'none';
document.getElementsByClassName("article-body__actions")[0].style.display = 'none';
document.getElementsByClassName("block_outlined-desktop")[0].style.display = 'none';
document.getElementsByClassName("block_outlined-desktop")[1].style.display = 'none';
document.getElementsByClassName("footer")[0].style.display = 'none';
}
////////////////////////////////////////////////////////////////////////////////
// Nicer Comment Navigation
function nicerCommentNavigation() {
var nc = document.getElementsByClassName("info_linear-mobile")[0].getElementsByTagName("a")[1].innerHTML.replace(/ .*/,'');
var pg = Math.ceil( parseInt(nc) / 50 );
var href = window.location.href.replace(/\/comment-page-[0-9]+/,'').replace(/\/#comments/,'');
var nav = ["above","below"];
for (var i = 0; i < nav.length; i++) {
var nl = document.getElementById("comment-nav-" + nav[i]).getElementsByClassName("nav-links")[0];
nl.innerHTML = '';
for (var j = 1; j <= pg; j++) {
var div = document.createElement('div');
var a = document.createElement('a');
div.setAttribute("class","nav-next");
div.appendChild(a);
a.href = href + '/comment-page-' + j + '/#comments';
a.innerHTML = j;
nl.appendChild(div);
}
}
}
////////////////////////////////////////////////////////////////////////////////
function mainCommenting() {
var comments = document.getElementById("comments");
if (! comments) {return;}
// Add the Recommend CCCP Link
var rec = document.createElement("a");
document.getElementById("cccp_rec").appendChild(rec);
rec.innerHTML = "Recommend CCCP";
rec.addEventListener("click", recommendCCCP, false);
// Add the CCCP Help Link
var hlp = document.createElement("a");
document.getElementById("cccp_hlp").appendChild(hlp);
hlp.innerHTML = "CCCP Help";
hlp.addEventListener("click", helpCCCP, false);
}
////////////////////////////////////////////////////////////////////////////////
// Create a new cccp_nav <div> with space for help/settings/recommend
function cccpNavBar() {
var comments = document.getElementById("comments");
if (! comments) {return;}
var cccp_nav = document.createElement('div');
cccp_nav.id = "cccp_nav";
comments.appendChild(cccp_nav);
var nav = ["hlp","set","rec"];
var alg = ["left","center","right"];
var tbl = document.createElement('table');
cccp_nav.appendChild(tbl);
var row = document.createElement('tr');
tbl.appendChild(row);
for (var i = 0; i < nav.length; i++) {
var td = document.createElement('td');
td.width = '33%';
row.appendChild(td);
var dv = document.createElement('div');
dv.id = 'cccp_' + nav[i];
dv.style = "text-align: " + alg[i] + ";";
td.appendChild(dv);
}
// Add the CCCP Settings Link
var set = document.createElement("a");
document.getElementById("cccp_set").appendChild(set);
set.innerHTML = "CCCP Settings";
set.addEventListener("click", showConfigCCCP, false);
}
////////////////////////////////////////////////////////////////////////////////
function recommendCCCP() {
var comment = document.getElementById("comment");
comment.value += '\nTo use the Crikey Clear Comment Preview script, install in order:\n';
comment.value += '<a href="' + ff[1] + '">Firefox</a>\n';
comment.value += '<a href="' + gm[1] + '">Greasemonkey</a>\n';
comment.value += '<a href="' + cc[1] + '">cccp</a>\n';
comment.value += 'or:\n';
comment.value += '<a href="' + gc[1] + '">Google Chrome</a>\n';
comment.value += '<a href="' + tm[1] + '">Tampermonkey</a>\n';
comment.value += '<a href="' + cc[1] + '">cccp</a>\n';
}
////////////////////////////////////////////////////////////////////////////////
function helpCCCP() {
alert('No Help for you! (TODO)');
}