forked from p01/pouet.net.user.js
/
onelinerUnicode.js
72 lines (51 loc) · 2.11 KB
/
onelinerUnicode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// ==UserScript==
// @name onelinerUnicode
// @namespace Pouet.net.user
// @description Fixes Unicodes not showing up in the so famous pouët.net oneliner
// @include http://www.pouet.net/*
// @include http://www.pouet.net/index.php
// @include http://www.pouet.net/oneliner.php
// ==/UserScript==
(function(){
"use strict";
fixOnelinerEncoding();
function fixOnelinerEncoding() {
var onelinerComment = getOneliner();
if(onelinerComment && (onelinerComment.length > 0)) {
for(var i = 0; i < onelinerComment.length; i++) {
var element = onelinerComment[i];
var comment = element.innerHTML;
//remove line breaks in &am..p;
comment = comment.replace(/(\r\n|\n|\r)/g, '');
//fix encoding problem - &#9829; => ♥
comment = comment.replace(/&#/g, '&#');
//this occours on the homepage oneliner - &amp;#9829; => ♥
comment = comment.replace(/&amp;#/g, '&#');
element.innerHTML = comment;
}
}
}
function hasClass(element, cls) {
return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
}
function getOneliner() {
//if only pouet wasn't such a birch to parse, this could be a oneliner
var oneliner = (document.querySelectorAll('img[title="talk"]'))[0],
onelinerLine,
onelinerComment = [];
if(oneliner) {
//this is horrible, but finds the table rows with comments, title and submit
oneliner = oneliner.parentNode.parentNode.parentNode;
//the complete oneliner even needs more parent() calls
if(!hasClass(oneliner.parentNode, 'box'))
oneliner = oneliner.parentNode.parentNode.parentNode.parentNode;
//use the user images and their link as hook, to get their parent <tr>
onelinerLine = oneliner.querySelectorAll('a[href^="user.php?who"]');
//go up two nodes to the <tr> then find the third <td>, this holds the comment (first <td> is the pic above)
for(var i = 0; i < onelinerLine.length; i++) {
onelinerComment.push( (onelinerLine[i].parentNode.parentNode).querySelectorAll('td:nth-child(3)')[0] );
}
}
return onelinerComment;
}
}());