Last active
October 16, 2018 20:32
-
-
Save Clorith/25846220b2815c727e85ab36324d0af6 to your computer and use it in GitHub Desktop.
WordPress.org plugins topic highlighter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="tamper-wp-topic-highlighter"> | |
<hr> | |
<strong>Topics older than 1 week with no resolution</strong> | |
<br> | |
<div style="display: inline-block; width: 30%;">Background: </div> | |
<div style="display: inline-block;"><input type="text" id="tamper-wp-topic-highlighter-old" value="#ffc173" style="padding: 0 5px;"></div> | |
<br> | |
<div style="display: inline-block; width: 30%;">Text: </div> | |
<div style="display: inline-block;"><input type="text" id="tamper-wp-topic-highlighter-old-text" value="inherit" style="padding: 0 5px;"></div> | |
<br><br> | |
<strong>Topics with no replies</strong> | |
<br> | |
<div style="display: inline-block; width: 30%;">Background: </div> | |
<div style="display: inline-block;"><input type="text" id="tamper-wp-topic-highlighter-new" value="#ffc173" style="padding: 0 5px;"></div> | |
<br> | |
<div style="display: inline-block; width: 30%;">Text: </div> | |
<div style="display: inline-block;"><input type="text" id="tamper-wp-topic-highlighter-new-text" value="inherit" style="padding: 0 5px;"></div> | |
<br><br> | |
<strong>Topics that are resolved</strong> | |
<br> | |
<div style="display: inline-block; width: 30%;">Background: </div> | |
<div style="display: inline-block;"><input type="text" id="tamper-wp-topic-highlighter-resolved" value="#ffc173" style="padding: 0 5px;"></div> | |
<br> | |
<div style="display: inline-block; width: 30%;">Text: </div> | |
<div style="display: inline-block;"><input type="text" id="tamper-wp-topic-highlighter-resolved-text" value="inherit" style="padding: 0 5px;"></div> | |
<p> | |
<button type="submit" class="button button-primary submit">Save options</button> | |
<button type="button" class="button cancel">Cancel</button> | |
<button type="reset" class="button reset">Restore defaults</button> | |
</p> | |
<hr> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name WordPress.org plugins and themes topic highlighter | |
// @namespace http://clorith.net/ | |
// @version 0.3 | |
// @description Add status highlights to topics for easy overviews. | |
// @author Clorith | |
// @match https://wordpress.org/support/plugin/* | |
// @match https://wordpress.org/support/theme/* | |
// @require https://code.jquery.com/jquery-1.11.0.min.js | |
// @resource configHtml https://gist.githubusercontent.com/Clorith/25846220b2815c727e85ab36324d0af6/raw/1744684e556f933a1def851dc760f207cb554df9/options.html | |
// @grant none | |
// ==/UserScript== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name WordPress.org plugins and themes topic highlighter | |
// @namespace http://clorith.net/ | |
// @version 0.3 | |
// @description Add status highlights to topics for easy overviews. | |
// @author Clorith | |
// @match https://wordpress.org/support/plugin/* | |
// @match https://wordpress.org/support/theme/* | |
// @require https://code.jquery.com/jquery-1.11.0.min.js | |
// @resource configHtml https://gist.githubusercontent.com/Clorith/25846220b2815c727e85ab36324d0af6/raw/1744684e556f933a1def851dc760f207cb554df9/options.html | |
// @grant none | |
// ==/UserScript== | |
jQuery(document).ready(function( $ ) { | |
/* | |
* The rules here are cascading, later rules will overwrite earlier ones. | |
* This is doen to ensure the right priority is applied, as some states are more important than others. | |
*/ | |
var text, $topics, | |
settings = { | |
color: { | |
resolved: { | |
background: 'rgb(203, 255, 181)', | |
text: 'inherit' | |
}, | |
new: { | |
background: '#ffeb00', | |
text: 'inherit' | |
}, | |
old: { | |
background: '#ffc173', | |
text: 'inherit' | |
} | |
} | |
}; | |
function process_topics() { | |
// Highlight topics that are more than a week old. | |
$topics = $( '.bbp-topic-freshness' ); | |
$topics.each(function() { | |
text = $( 'a', $(this) ).text(); | |
if ( text.includes( 'week' ) || text.includes( 'month' ) || text.includes( 'year' ) ) { | |
$(this).closest( 'ul' ).css( 'background-color', settings.color.old.background ); | |
$( 'a', $( this ).closest( 'ul' ) ).css( 'color', settings.color.old.text ) | |
} | |
}); | |
// Highlight topics not yet replied to. | |
$topics = $( '.bbp-topic-voice-count' ); | |
$topics.each(function() { | |
text = $(this).text(); | |
if ( '1' === text ) { | |
$(this).closest( 'ul' ).css( 'background-color', settings.color.new.background ); | |
$( 'a', $( this ).closest( 'ul' ) ).css( 'color', settings.color.new.text ); | |
} | |
}); | |
// Highlight resolved threads. | |
$( 'span.resolved' ).closest( 'ul' ).css( 'background-color', settings.color.resolved.background ); | |
$( 'a', $( 'span.resolved' ).closest( 'ul' ) ).css( 'color', settings.color.resolved.text ) | |
} | |
function set_colors() { | |
var stored = localStorage.getItem( 'wp_highlighter' ); | |
if ( null !== stored ) { | |
settings = JSON.parse( stored ); | |
} | |
} | |
// Set up color choices. | |
set_colors(); | |
// Run processer. | |
process_topics(); | |
// Add options link to the sidebar. | |
$( '.entry-meta.sidebar div:first-of-type ul' ).append( '<li><a href="#" id="tamper-show-options">Highlighter Options</a></li>' ); | |
// Trigger options form display | |
$(".entry-meta").on( 'click', '#tamper-show-options', function( e ) { | |
e.preventDefault(); | |
$( '#bbpress-forums' ).prepend( GM_getResourceText( 'configHtml' ) ); | |
$( '#tamper-wp-topic-highlighter-resolved' ).val( settings.color.resolved.background ); | |
$( '#tamper-wp-topic-highlighter-resolved-text' ).val( settings.color.resolved.text ); | |
$( '#tamper-wp-topic-highlighter-new' ).val( settings.color.new.background ); | |
$( '#tamper-wp-topic-highlighter-new-text' ).val( settings.color.new.text ); | |
$( '#tamper-wp-topic-highlighter-old' ).val( settings.color.old.background ); | |
$( '#tamper-wp-topic-highlighter-old-text' ).val( settings.color.old.text ); | |
}); | |
// Save options | |
$( '#page' ).on( 'submit', '#tamper-wp-topic-highlighter', function( e ) { | |
e.preventDefault(); | |
settings.color.resolved.background = $( '#tamper-wp-topic-highlighter-resolved' ).val(); | |
settings.color.resolved.text = $( '#tamper-wp-topic-highlighter-resolved-text' ).val(); | |
settings.color.new.background = $( '#tamper-wp-topic-highlighter-new' ).val(); | |
settings.color.new.text = $( '#tamper-wp-topic-highlighter-new-text' ).val(); | |
settings.color.old.background = $( '#tamper-wp-topic-highlighter-old' ).val(); | |
settings.color.old.text = $( '#tamper-wp-topic-highlighter-old-text' ).val(); | |
localStorage.setItem( 'wp_highlighter', JSON.stringify( settings ) ); | |
$( this ).remove(); | |
// Re-process topics after making edits. | |
process_topics(); | |
}).on( 'click', '.cancel', function( e ) { | |
e.preventDefault(); | |
$( this ).closest( 'form' ).remove(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment