Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name mirko-tag-fixer
- // @version 0.1
- // @description Tag extractor from spoiler content
- // @author deviolin
- // @match http://www.wykop.pl/mikroblog/*
- // ==/UserScript==
- var entries = document.querySelectorAll('div[data-type="entry"] .text'),
- hash = document.createTextNode('#'),
- space = document.createTextNode(' ');
- each(entries, function (entry) {
- var tags = entry.querySelectorAll('.dnone .showTagSummary'),
- p = document.createElement('p');
- if (tags.length > 0) {
- each(tags, function (tag) {
- replaceText(tag);
- p.appendChild(hash.cloneNode());
- p.appendChild(tag);
- p.appendChild(space.cloneNode());
- });
- entry.insertBefore(p, entry.firstChild);
- }
- });
- // Utils
- function replaceText(node) {
- var element = node.previousSibling ? node.previousSibling : node.parentElement.previousSibling;
- element.textContent = element.textContent.replace('#', '');
- }
- function each(collection, callback) {
- Array.prototype.forEach.call(collection, callback);
- }
Advertisement
Add Comment
Please, Sign In to add comment