JustAnOrdinaryCoder / Huffington Datascrape

// ==UserScript==
// @name         Huffington Datascrape
// @namespace    JustAnOrdinaryCoder
// @version      1.0
// @description  Huffington Post Datascraper
// @author       JustAnOrdinaryCoder
// @match        http://www.huffingtonpost.com/*
// @grant        none
// ==/UserScript==

var o;
var x = document.documentElement.outerHTML;
var blackList = ["―&nbsp;", "<p>", "undefined", "<a rel=", "noopener noreferrer", " target=", "_blank", " href=\"", '\"', "\\", "</a>"];
function nthIndex(str, pat, n){
    var L= str.length, i= -1;
    while(n-- && i++<L){
        i= str.indexOf(pat, i);
        if (i < 0) break;
    }
    return i;
}
for(i = 1; i < 99; i++){
	if(nthIndex(x, "<p>", i) == -1){
		break;
	}
	helper = nthIndex(x, "<p>", i);
	o += x.substring(helper, x.indexOf("</p>", helper)) + " ";
}

d = 13;
for(i = 0; i < blackList.length; i++){
	if(i == 1 || i == 8 || i == 9){
		d = 200;
	} else {
		d = 13;
	}
	for(please = 0; please < d; please++){
		o = o.replace(blackList[i], "");
	}
}

for(i = 1; i <= 20; i++){
	if(nthIndex(o, "href=", i) == -1){
		break;
	}
	helper = nthIndex(o, "href=", i);
	o = o.replace((o.substring(helper, o.indexOf(">", helper))), "");
}
for(i = 1; i <= 20; i++){
	if(nthIndex(o, "href=", i) == -1){
		break;
	}
	helper = nthIndex(o, "href=", i);
	o = o.replace((o.substring(helper, o.indexOf("/>", helper))), "");
}
blackList = [" >", "We tell big stories on difficult subjects.", "We’ve reported on the inequities of the drug treatment system, deaths in police custody, and a massive bribery scandal involving some of the world’s biggest corporations.", "To tell these stories, we must work with people who know what is really going on inside government and private institutions.",  "That’s where you come in.", "Are you getting new directives that flout established practice?", "Are new rules making you uncomfortable?", "Is an important program on the chopping block?", "Are you being asked to do something unethical?", "We want to see whatever evidence and documentation you can provide.",  "Your employer, hackers and the government can all read your emails (or at least see that you contacted us).", "If you’re concerned that being a source for a story poses a significant risk, take precautions: In most cases, our reporters or editors will need to know your identity so we can verify and authenticate the information you provide to us.", "We understand the risks that sources may be taking, and we will discuss with the source any additional steps we may need to take to protect anonymity.",  "We will absolutely stand behind any agreement we may make to protect your identity.", "If you instead feel you must remain completely anonymous, we will ask you to provide us with sources or contacts who can corroborate the information you send us.\"", "But if that doesn’t bother you, email us at", "href=mailto:scoops@huffingtonpost.comscoops@huffingtonpost.com.", "If you instead feel you must remain completely anonymous, we will ask you to provide us with sources or contacts who can corroborate the information you send us.", "href=", "mailto:", "scoops@huffingtonpost", ".comscoops@huffingtonpost", ".com.", ".com"];
for(i = 0; i < blackList.length; i++){
	for(please = 0; please < 3; please++){
		o = o.replace(blackList[i], "");
	}
}
for(i = 1; i != -1; i){
	if(nthIndex(o, "<a", i) == -1){
		break;
	}
	helper = nthIndex(o, "<a", i);
	o = o.replace((o.substring(helper, o.indexOf(">", helper))), "");
}
blackList = ["&nbsp;", ">", " />"];
for(i = 0; i < blackList.length; i++){
	for(please = 0; please < 50; please++){
		o = o.replace(blackList[i], "");
	}
}
o += "|||URL: "+ window.location.href;
helper = nthIndex(x, "<h1 class=\"headline__title", 1);
titleBlack = ["-h1 class=-headline__title--"];
var title = x.substring(helper, x.indexOf("</h1>", helper));
title = title.substring(28);
var textToSave = o;

var hiddenElement = document.createElement('a');

hiddenElement.href = 'data:attachment/text,' + encodeURI(textToSave);
hiddenElement.target = '_blank';
hiddenElement.download = title + '.txt';
hiddenElement.click();
window.close();