Last active
August 2, 2018 10:57
-
-
Save mithro/e60a3f8b62696d1cff12dbb7e1377c47 to your computer and use it in GitHub Desktop.
GreaseMonkey / TamperMonkey script to make Linux.conf.au (Symposium) reviews a bit nicer
This file contains 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 symposium-review-extra | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description Show all the tabs in the review pane at once. | |
// @author You | |
// @match https://rego.linux.conf.au/reviews/review/.* | |
// @match https://rego.linux.conf.au/reviews/review/* | |
// @downloadURL https://gist.github.com/mithro/e60a3f8b62696d1cff12dbb7e1377c47.js | |
// @updateURL https://gist.github.com/mithro/e60a3f8b62696d1cff12dbb7e1377c47.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Import showdown for markdown rendering... | |
var imported = document.createElement('script'); | |
imported.src = 'https://cdnjs.cloudflare.com/ajax/libs/showdown/1.7.2/showdown.min.js'; | |
imported.onload = function() { | |
// Convert the comments from markdown | |
renderMarkdownComments(document.getElementsByClassName("review-content")); | |
}; | |
document.head.appendChild(imported); | |
function renderMarkdownComments(elements) { | |
var converter = new showdown.Converter(); | |
for (var i=0, len=elements.length; i<len; i++) { | |
// Find the element which has the actual comment in it | |
var n = elements[i].childNodes; | |
var last = n[n.length-1]; | |
// Render the element into HTML | |
var element = document.createElement('div'); | |
element.innerHTML = converter.makeHtml(last.data.trim()); | |
last.replaceWith(element); | |
} | |
} | |
function display(elements, value){ | |
for (var i=0, len=elements.length; i<len; i++) { | |
elements[i].style["display"] = value; | |
} | |
} | |
if (document.getElementById("proposal-detail") !== null) { | |
// Show all tabs | |
console.log("Enabling all tabs"); | |
document.getElementById("proposal-detail").classList.add("active"); | |
document.getElementById("proposal-reviews").classList.add("active"); | |
document.getElementById("proposal-feedback").classList.add("active"); | |
// Move the review form to a better location | |
var f = document.getElementsByClassName("review-form")[0]; | |
f.parentNode.removeChild(f); | |
var pd = document.getElementById("proposal-detail"); | |
pd.appendChild(f); | |
// Add a button to show/hide other people's reviews | |
if (document.getElementById("reviews") === null) { | |
console.log("Adding show/hide reviews button"); | |
var btn = document.createElement("button"); | |
btn.id = "reviews"; | |
btn.onclick = function() { | |
var elements = document.getElementsByClassName("review-box"); | |
if (elements[0].style["display"] == "none") { | |
display(elements, ""); | |
elements[elements.length-1].scrollIntoView(); | |
} else { | |
display(elements, "none"); | |
} | |
}; | |
var t = document.createTextNode("Show/Hide Reviews"); | |
btn.appendChild(t); | |
document.getElementById("proposal-detail").appendChild(btn); | |
// Hide other people's review by default | |
//display(document.getElementsByClassName("review-box"), "none"); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment