Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
WordPress.com Support Forums Post Analyzer
// ==UserScript==
// @name WordPress.com Support Forums Post Analyzer
// @namespace http://tampermonkey.net/
// @version 0.3.3
// @description Displays number of member posts,auto-checks the subscribe button, checks for new posts, tag buttons, added Google Forum Search
// @author Terry Brownell aka joerepublic
// @match https://en.forums.wordpress.com/topic/*
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
var buttontags = ['modlook', 'duplicate', 'mapping', 'billing','css', 'wp.org', 'themes', 'wordads', 'spam', 'delete account', 'delete site', 'domain', 'transfer'];
var intervaltime = 5000;
var timeout = 420000; //420000 = 7 minutes
(function() {
'use strict';
$(document).ready(function() {
//Check subscription box
$('#subscription_checkbox').prop('checked', true);
//Add tag buttons
$.each(buttontags, function(i, thetag){
var newnode = document.createElement ('div');
newnode.setAttribute("id", "tagbuttons");
newnode.innerHTML = '<button id="'+thetag+'" type="button" style="float: right;margin: 20px 0px 20px 10px; border-radius: 11px;font-size: 11px; line-height: 21px; padding: 0 10px;">'+thetag+'</button>';
$('.footerwrap').before(newnode);
document.getElementById (thetag).addEventListener (
"click", clickyclicky, false
);
function clickyclicky (nodeevent) {
$('#tag').val(thetag);
$('#tagformsub').click();
}
});
//Total thread count of OP, display by membername
var profileurl = $('.authortitle:first a');
var href = $(profileurl).attr('href');
$.get(href, function(data){
var postcount = $(data).find('ol li').length;
$('.threadauthor:first strong').append("<span style='margin-left: 10px;'>"+postcount+"</span>");
});
//Checks for updates to this post, edits button if new response, displays last post.
var origcount = $("body").find('ol li').length;
var intervalfunk = setInterval(function () {
$.get(window.location.href, function(data){
var newcount = $(data).find('ol li').length;
if(origcount < newcount){
$('#postformsub').prop('value', 'Submit *NEW*');
$('#postformsub').css('color', 'red');
origcount = newcount;
var thelastpost = $(data).find('ol li').last();
$('.footerwrap').before(thelastpost);
clearInterval(intervalfunk);
}
});
},intervaltime);
//Timeout the response updater.
function clearit(){
clearInterval(intervalfunk);
$('#tagbuttons').before("<b style='float:right;color:red'>No longer checking for updated responses!</b>");
}
setTimeout(clearit, timeout);
//Add a google support forum search box
$('.tags').after('<form action="http://www.google.com/search" method="get" name="searchform" target="_blank" style="margin-top:25px;"><input name="sitesearch" type="hidden" value="en.support.wordpress.com"><input autocomplete="on" name="q" placeholder="Google Forum Search" required="required" type="text"><button style="border-radius: 11px;font-size: 11px; line-height: 21px; padding: 0 10px;" type="submit">Go Google Go!</button></form>');
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment