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.00
// ==/UserScript==
// Ver 5.00
// New major version to deal with New, souped-up Crikey
////////////////////////////////////////////////////////////////////////////////
/*jslint browser: true */
/*global GM_config, GM_registerMenuCommand */
////////////////////////////////////////////////////////////////////////////////
var scriptVer = '5.00';
var scriptLoc = 'https://greasyfork.org/en/scripts/18677-crikeycleancommentpreview';
//don't run in iframes
if (window.top !== window.self) {
return;
}
////////////////////////////////////////////////////////////////////////////////
// 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() {
console.log('mainCommenting()');
}
////////////////////////////////////////////////////////////////////////////////
// Create a new cccp_nav <div> with space for help/settings/recommend
function cccpNavBar() {
var comments = document.getElementById("comments");
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);
}