Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DemoJameson/1588021b763721a188796b75aafa853c to your computer and use it in GitHub Desktop.
Save DemoJameson/1588021b763721a188796b75aafa853c to your computer and use it in GitHub Desktop.
去除 Kotlin 中文站文档多余空格
// ==UserScript==
// @name 去除 Kotlin 中文站文档多余空格
// @namespace http://demojameson.com/remove-kotlin-cn-doc-unnecessary-space
// @version 0.2
// @description 去除 Kotlin 中文站文档多余空格
// @author DemoJameson
// @match https://www.kotlincn.net/docs/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var ELEMENT = 1;
var TEXT_NODE = 3;
removeTextNodeNewLine(document.body);
function removeTextNodeNewLine(element){
if (element.nodeType === ELEMENT) {
if (element.tagName === 'CODE' || element.tagName === 'PRE') return;
element.childNodes.forEach(function(child){ removeTextNodeNewLine(child);});
} else if (element.nodeType === TEXT_NODE) {
element.textContent = element.textContent.replace(/\n/g, '');
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment