Skip to content

Instantly share code, notes, and snippets.

@emk
Created September 26, 2012 17:49
Show Gist options
  • Save emk/3789478 to your computer and use it in GitHub Desktop.
Save emk/3789478 to your computer and use it in GitHub Desktop.
HTLAL Fixups (userscript for Chrome)
// ==UserScript==
// @name HTLAL Fixups
// @description Make how-to-learn-any-language.com work a bit better.
// @match http://how-to-learn-any-language.com/*
// ==/UserScript==
// Fix word-wrap in textareas, so URLs don't get broken and posts don't get
// formatted strangely.
var textareas = document.getElementsByTagName("textarea");
for (var i = 0; i < textareas.length; i++) {
var textarea = textareas[i];
textarea.removeAttribute("wrap");
}
// Find anchors for specific comments.
var anchors = document.querySelectorAll("a[name]");
var commentAnchors = new Array();
for (var i = 0; i < anchors.length; i++) {
var a = anchors[i];
if (a.getAttribute("name").match(/^\d+$/)) {
commentAnchors.push(a);
}
}
// Add permalinks to each post.
for (var i = 0; i < commentAnchors.length; i++) {
var a = commentAnchors[i];
var name = a.getAttribute("name");
var permalink = document.createElement("a");
var text = document.createTextNode("permalink");
permalink.appendChild(text);
permalink.setAttribute("href", "#" + name);
// Carefully attach it
var tr = a.parentNode.parentNode;
if (tr.nodeName.toLowerCase() === "tr") {
var td = tr.children[tr.children.length-1];
if (td.nodeName.toLowerCase() === "td") {
var spacer = document.createTextNode(" | ");
td.appendChild(spacer);
td.appendChild(permalink);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment