// ==UserScript==
// @name blogs
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @include https://forums.taleworlds.com/index.php/board,253*
// @include https://www.taleworlds.com/en/Shared/AllNewsPartial?section=6&pageIndex=1&pageSize=1000*
// @include https://forums.taleworlds.com/index.php?*
// @grant none
// ==/UserScript==
var curWindow = window.location.href;
var segs = "x.y";
let threadLinkStrings = [];
let usableThreadLinks = [];
let entryTitlesDesc = [];
let entryTitlesAsc = [];
if(curWindow !== null && curWindow !== undefined && curWindow !== ""){
var segs = curWindow.match(/\w{1,}/g);
}
if (window.innerWidth > 2 && window.innerHeight > 2) {
let threadLinks = document.getElementsByTagName("a");
for(let j=0;j<threadLinks.length;j++){
if(threadLinks[j].innerText.match(/Dev Blog/g) && threadLinks[j].href.match(/topic/g) && threadLinks[j].href.match(/[.]{1}0[.]{1}/g) && !threadLinks[j].href.match(/msg/g)){
usableThreadLinks[usableThreadLinks.length] = threadLinks[j];
let parentEl = threadLinks[j].parentElement;
let smallBtn = document.createElement("button");
smallBtn.innerText = "More";
smallBtn.style.background = "url('https://forums.taleworlds.com/Themes/TWcurve/images/theme/menu_gfx.png')";
smallBtn.addEventListener("click", function(event){
event.preventDefault();
});
smallBtn.addEventListener("click", function(event){
let parent = event.target.parentElement;
let aElement = parent.getElementsByTagName("a")[0];
var xhttp = new XMLHttpRequest();
xhttp.open("GET", aElement.href, true);
xhttp.send();
setTimeout(function(){
if(!aElement.innerText.match(/ - Blog /g)){
let firstPage = xhttp.responseText;
let blogPic = firstPage.match(/blog_post/g)[0];
let entryNo = parseInt(firstPage.match(/blog_post_\d{1,}_taleworldswebsite/g)[0].match(/\d{1,}/g)[0])+16;
let miniFrame = document.createElement("iframe"); // because sending requests didn't work
miniFrame.id = "mini";
miniFrame.width=2;
miniFrame.height=2;
miniFrame.src = "https://forums.taleworlds.com/index.php?no="+entryNo;
document.body.appendChild(miniFrame);
let txt = aElement.innerText;
aElement.innerText = txt + " - Blog " + entryNo;
setTimeout(function(){
let mf = document.getElementById("mini");
txt = aElement.innerText;
let cleanTitle = decodeURI(mf.src.substring(40));
aElement.innerText = txt + ": " + cleanTitle;
mf.remove();
},6000);
}
},600); // give enough time for the site to load
});
parentEl.appendChild(smallBtn);
}
}
}
else if (segs[1] == "forums" && location.href.match(/[?]{1}no[=]{1}/g)){
location.assign("https://www.taleworlds.com/en/Shared/AllNewsPartial?section=6&pageIndex=1&pageSize=1000&"+ segs[7] );
setTimeout(function(){
},10000);
}
else if(segs[1]=="www"){
let lnks=document.getElementsByTagName("a");
for(let i=0;i<lnks.length;i++){
let lnkTitle = lnks[i].innerText;
if(lnkTitle != "Mount & Blade II: Bannerlord at E3 2017 – Reactions"
&& lnkTitle != "Mount & Blade II: Bannerlord - Battles and Combat Detailed at E3"
&& lnkTitle != "Mount & Blade II: Bannerlord at E3 2017 – Where to Watch"
&& lnkTitle != "Mount & Blade II: Bannerlord Playable At E3 2017"
&& lnkTitle != "Mount & Blade II: Bannerlord Featured on PC Gamer Magazine Cover!"
&& lnkTitle != "Mount & Blade II: Bannerlord on Steam"
&& lnkTitle != "Mount & Blade II: Bannerlord @ Gamescom 2016"
&& lnkTitle != "Bannerlord Sieges Revealed at E3"
&& lnkTitle != "Mount & Blade II: Bannerlord at E3 2016"
&& lnkTitle != "Rock, Paper, Shotgun Interview!"
&& lnkTitle != "40 minutes of gameplay at PC Gamer Weekender"
&& lnkTitle != "Mount & Blade II: Bannerlord – First glimpse"
&& lnkTitle != "Mount & Blade II: Bannerlord at E3 2016"
&& lnkTitle != "Mount&Blade II: Bannerlord Announcement!"){
entryTitlesDesc[entryTitlesDesc.length] = lnkTitle;
}
}
entryTitlesAsc = entryTitlesDesc.reverse();
location.replace("https://forums.taleworlds.com/index.php?" + entryTitlesAsc[segs[13]-1]);
}
else if (segs[1] == "forums" && !location.href.match(/[?]{1}no[=]{1}/g)){
let frm = window.frameElement;
if(frm.src != location.href){
frm.src = location.href;
}
}