Created
August 4, 2016 07:36
-
-
Save garo/02f3c96f6af4ea2999b3c244de5412a2 to your computer and use it in GitHub Desktop.
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 Palringo hax for assembly by Garo | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Tampermonkey script which modifies Palringo feedback page so that it's suitable for easy copy-pasting into Eilium. Used in Assembly Summer 2016 | |
// @author Garo | |
// @match http://www.palringo.com/en/gb/feedback | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function copyToClipboard(elem) { | |
// create hidden text element, if it doesn't already exist | |
var targetId = "_hiddenCopyText_"; | |
var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA"; | |
var origSelectionStart, origSelectionEnd; | |
var target = null; | |
if (isInput) { | |
// can just use the original source element for the selection and copy | |
target = elem; | |
origSelectionStart = elem.selectionStart; | |
origSelectionEnd = elem.selectionEnd; | |
} else { | |
// must use a temporary form element for the selection and copy | |
target = document.getElementById(targetId); | |
if (!target) { | |
target = document.createElement("textarea"); | |
target.style.position = "absolute"; | |
target.style.left = "-9999px"; | |
target.style.top = "0"; | |
target.id = targetId; | |
document.body.appendChild(target); | |
} | |
target.textContent = elem.textContent; | |
} | |
// select the content | |
var currentFocus = document.activeElement; | |
target.focus(); | |
target.setSelectionRange(0, target.value.length); | |
// copy the selection | |
var succeed; | |
try { | |
succeed = document.execCommand("copy"); | |
} catch(e) { | |
succeed = false; | |
} | |
// restore original focus | |
if (currentFocus && typeof currentFocus.focus === "function") { | |
currentFocus.focus(); | |
} | |
if (isInput) { | |
// restore prior selection | |
elem.setSelectionRange(origSelectionStart, origSelectionEnd); | |
} else { | |
// clear temporary content | |
target.textContent = ""; | |
} | |
return succeed; | |
} | |
$('#feedback-table > thead > tr').each(function() { | |
arguments[1].children[1].innerHTML = "Click column to copy to clipboard"; | |
}); | |
$('#feedback-table > tbody > tr').each(function() { | |
var nicktd = arguments[1].children[0]; | |
var nickregexp = /^(.+?)\s[0-9]+$/; | |
var nickm = nickregexp.exec(nicktd.innerHTML); | |
var nick = nickm[1]; | |
var feedback = arguments[1].children[2].innerHTML; | |
var group = arguments[1].children[1]; | |
group.innerHTML = nick.trim() + ": " + feedback.trim(); | |
group.addEventListener("click", function(event) { | |
copyToClipboard(event.toElement); | |
}); | |
}); | |
console.log("Garo's Palringo Assembly hack script is loaded"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment