Skip to content

Instantly share code, notes, and snippets.

@qnighy
Last active January 26, 2017 07:25
Show Gist options
  • Save qnighy/1035c877f17956da04a9 to your computer and use it in GitHub Desktop.
Save qnighy/1035c877f17956da04a9 to your computer and use it in GitHub Desktop.
Algebraic Topology Literature: strip unnecessary spaces
// ==UserScript==
// @name Algebraic Topology Literature: strip unnecessary spaces
// @namespace http://qnighy.github.io/
// @version 0.1
// @description "Algebraic Topology, A Guide To Literature" is a very useful site, but the layout of japanese characters is disastrous. This UserJS relaxes the problem.
// @author Masaki Hara
// @match http://pantodon.shinshu-u.ac.jp/topology/literature/*
// @grant none
// ==/UserScript==
function elimText(node) {
var childNodes = new Array(node.childNodes.length);
for(var i = 0; i < node.childNodes.length; ++i) {
childNodes[i] = node.childNodes[i];
}
for(var i = 0; i < childNodes.length; ++i) {
var child = childNodes[i];
if(child.nodeType == 1) {
// node
elimText(child);
} else if(child.nodeType == 3) {
if(child.data.match(/^\s*$/)) {
node.removeChild(child);
} else {
var isja = false;
for(var j = 0; j < node.classList.length; ++j) {
var cl = node.classList[j];
if(cl.match(/dmj/)) {
isja = true;
}
}
if(isja) {
child.data = child.data.replace(/^\s+/, "").replace(/\s+$/, "");
}
}
}
}
}
elimText(document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment