Skip to content

Instantly share code, notes, and snippets.

@trent2
Last active February 22, 2022 06:47
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save trent2/4f1198a173019103478cbefbcaf4c744 to your computer and use it in GitHub Desktop.
Save trent2/4f1198a173019103478cbefbcaf4c744 to your computer and use it in GitHub Desktop.
Unobfuscate SPIEGEL plus articles with greasemonkey
// ==UserScript==
// @name unobfuscate spiegel plus
// @namespace obfuscate
// @include http://www.spiegel.de/*
// @version 1
// @grant none
// ==/UserScript==
if(document.getElementsByClassName('obfuscated-content')[0] != undefined) {
document.getElementsByClassName('obfuscated-content')[0].setAttribute("class", "");
var elems = document.getElementsByClassName('obfuscated'), t, or, c, i, cc;
for(i in elems) {
or = elems[i].innerHTML;
t = "";
inElement = false;
openTag = -1;
isATag = false;
closingTag = false;
dontTranslate = false;
if(or != undefined)
for(c=0; c<or.length; ++c) {
if(openTag>-1)
openTag++;
cc = or.charCodeAt(c);
if(cc == 60) { // "<"
dontTranslate = true;
inElement = true;
openTag = 0;
}
if(cc>33 && !dontTranslate) {
switch(cc) {
case 180: t += ";"; break;
case 178: t += "!"; break;
case 177: t += "&"; break;
default:
t += String.fromCharCode(cc-1);
}
}
else
t += or.charAt(c);
if(openTag==1 && cc == 97) // <a ...
isATag = true;
if(openTag==1 && cc == 47) // "</"
closingTag = true;
if(inElement && cc == 62) { // "<...>"
dontTranslate = isATag && !closingTag;
isATag = false;
inElement = closingTag = false;
openTag = -1;
}
}
elems[i].innerHTML = t;
}
}
@sp00n
Copy link

sp00n commented Jun 29, 2016

@trent2
Copy link
Author

trent2 commented Jul 1, 2016

Fixed.

@cyberpunkbln
Copy link

Hi,

i work on converting it to a Bookmarklet and i have some Problems.

The simple removing of the main-class
var obfcontdiv = document.getElementsByClassName('obfuscated-content');
don't functioned in pure vanilla javascript. I think greasemonkey remove this css-class before other javascripts can activated. When i remove this class after full-loading-event nothing happens.

At the moment i work on the Firefox-Webconsole:).

Is it possible to convert your Userscript to an Bookmarklet?

thx

@trent2
Copy link
Author

trent2 commented Aug 18, 2016

I don't exactly understand what you mean by "vanilla javascript". You're right that greasemonkey apparently kicks in before any other SO-JS is executed and removes the blurring of the subsequent element.
When you don't have GM running, SO loads and executes a script from laterpay.net. This wraps the "obfuscated-content"-div-element in another div-element with a random class-name with the associated blurring CSS-code effectively preventing any JS-code run afterwards from accessing the element with the associated blurring CSS. So if you execute your bookmarklet after the laterpay-script has been executed you won't be able to undo the blurring with the line you quoted.
Possible fixes:

  • You could use the ff addon NoScript and prevent SO from loading the laterpay.net-script. Then you should be able to execute the bookmarklet.
  • instead of the quoted line, use something like

var p = document.getElementsByClassName('obfuscated-content')[0].parentElement;
p.setAttribute("class", "");
p.nextElementSibling.style.display = "none";

to access the parent element created by the laterpay.net-script (and the following element). I have run this through the closure compile service at google and get something like this which works for me as a bookmarklet (with "javascript"-prefix):
var a=document.getElementsByClassName("obfuscated-content")[0].parentElement;a.setAttribute("class","");a.nextElementSibling.style.display="none";var b=document.getElementsByClassName("obfuscated"),c,d,e,f,g; for(f in b){d=b[f].innerHTML;c="";inElement=!1;openTag=-1;dontTranslate=closingTag=isATag=!1;for(e=0;e<d.length;++e){-1<openTag&&openTag++;g=d.charCodeAt(e);60==g&&(inElement=dontTranslate=!0,openTag=0);if(33<g&&!dontTranslate)switch(g){case 180:c+=";";break;case 178:c+="!";break;case 177:c+="&";break;default:c+=String.fromCharCode(g-1)}else c+=d.charAt(e);1==openTag&&97==g&&(isATag=!0);1==openTag&&47==g&&(closingTag=!0);inElement&&62==g&&(dontTranslate=isATag&&!closingTag,inElement=closingTag=isATag= !1,openTag=-1)}b[f].innerHTML=c};

Have fun!

@sindbad103
Copy link

Funktioniert auch heute noch einwandfrei. Vielen Dank.

@trent2
Copy link
Author

trent2 commented May 28, 2018

Ab heute nicht mehr :-)

@N00B2
Copy link

N00B2 commented Feb 21, 2022

Is there any option left?

@trent2
Copy link
Author

trent2 commented Feb 21, 2022

What kind of option?
About four years ago, Spiegel online changed the way Spiegel plus pages are displayed. Before, they send all content of the articel to the user, pretty lamely encrypted (rather obfuscated) for those not logged in, very easily to decypher.
From then on 95% of the article's text is not send to the web client at all if you're not logged in as a paying user, not even obfuscated or encrypted. This (old) script is purely running on your client, i.e. probably your web browser. You cannot decrypt anything from nothing.

@N00B2
Copy link

N00B2 commented Feb 22, 2022

Makes sense, those fuckers...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment