Skip to content

Commit

Permalink
Merge branch 'next-page-links' into chrome-extension-tidy-up
Browse files Browse the repository at this point in the history
  • Loading branch information
madman-bob committed Sep 15, 2017
2 parents 1b9076a + 0282544 commit 7826ff2
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 87 deletions.
92 changes: 5 additions & 87 deletions POV Cam/injection.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,3 @@
function createLink(link) {
var name = peoplenames[link[0]];
var colour = colours[link[1]];
var image = images[link[2]];
var nextPages = link[4];

var container = document.createElement("div");

if (nextPages.length == 0) {
var personIcon = document.createElement("img");
personIcon.src = chrome.extension.getURL("images/" + image);
personIcon.width = 32;
personIcon.height = 32;
personIcon.style["vertical-align"] = "middle";
personIcon.title = name;
container.appendChild(personIcon);

var enterCommand = document.createElement("span");
enterCommand.innerText = "> ";
container.appendChild(enterCommand);

return container;
}

while (nextPages.length > 0) {
var nextPage = nextPages.pop();
var nextPageNo = nextPage[0];
var nextPageIndex = nextPage[1];
var nextPageCaption = name;
if (nextPage.length == 4) {
nextPageCaption = nextPageCaption + " - " + nextPage[2];
}

var innerContainer = document.createElement("div");

var personIcon = document.createElement("img");
personIcon.src = chrome.extension.getURL("images/" + image);
personIcon.width = 32;
personIcon.height = 32;
personIcon.style["vertical-align"] = "middle";
personIcon.title = nextPageCaption;
innerContainer.appendChild(personIcon);

var enterCommand = document.createElement("span");
enterCommand.innerText = "> ";
innerContainer.appendChild(enterCommand);

var link = document.createElement("a");
link.href = "/?s=6&p=" + zeroPad(nextPageNo);
link.hash = nextPageIndex;
link.title = nextPageCaption;

if ((document.location.pathname == "/trickster.php") && (pageCaptions[nextPageNo].indexOf("==>") != -1)) {
// In trickster section, replace "==>" in page name with sucker image
link.innerHTML = pageCaptions[nextPageNo].replace("==>", "");

var sucker = document.createElement("img");
sucker.src = "http://mspaintadventures.com/images/trickster_sitegraphics/sucker.gif";
sucker.style.backgroundColor = colour;
sucker.style.boxShadow = "0px 0px 2px 2px " + colour;

link.appendChild(sucker);
} else if (name.indexOf("English") != -1) {
// Give Lord English, Jack English colourful links
link.appendChild(lordEnglishText(pageCaptions[nextPageNo]));
} else {
link.innerText = pageCaptions[nextPageNo];
}

link.style.color = colour;
innerContainer.appendChild(link);

container.appendChild(innerContainer);
}

return container;
}

function zeroPad(pageNo) {
return ("00" + pageNo).slice(-6);
}

function modifyPage() {
if (document.location.pathname == "/DOTA/") {
pageNo = 6715;
Expand Down Expand Up @@ -160,13 +78,13 @@ function modifyPage() {
}, function (items) {
// Add links to page
for (var i in timelines[pageNo]) {
var currentgroup = groups[timelines[pageNo][i][3]];
if (items.timelinesenabled[currentgroup] != false) {
currentlink = createLink(timelines[pageNo][i]);
var linkData = new LinkData(timelines[pageNo][i]);
if (items.timelinesenabled[linkData.group] != false) {
var currentLink = createLink(linkData);
if ("#" + i == document.location.hash) {
nextPageLink = currentlink.getElementsByTagName("a")[0];
nextPageLink = currentLink.getElementsByTagName("a")[0];
}
linkContainer.appendChild(currentlink);
linkContainer.appendChild(currentLink);
}
}

Expand Down
1 change: 1 addition & 0 deletions POV Cam/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"timelines.js",
"page-captions.js",

"next-page-links.js",
"arrow-navigation.js",
"lord-english-text.js",
"pre-retcon-images/pre-retcon-images.js",
Expand Down
101 changes: 101 additions & 0 deletions POV Cam/next-page-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
function zeroPad(pageNo) {
return ("00" + pageNo).slice(-6);
}

class LinkData {
constructor(rawLinkData) {
this.name = peoplenames[rawLinkData[0]];
this.colour = colours[rawLinkData[1]];
this.image = images[rawLinkData[2]];
this.group = groups[rawLinkData[3]];
this.nextPages = rawLinkData[4].map(rawNextPageData => new DestinationLink(rawNextPageData));
}

createIcon(caption) {
var icon = document.createElement("img");
icon.src = chrome.extension.getURL("images/" + this.image);
icon.width = 32;
icon.height = 32;
icon.style["vertical-align"] = "middle";
icon.title = caption;

return icon;
}

static createAnonCommandPrompt() {
var commandPrompt = document.createElement("span");
commandPrompt.innerText = "> ";
return commandPrompt;
}

createCommandPrompt(caption) {
var container = document.createElement("div");

container.appendChild(this.createIcon(caption));
container.appendChild(LinkData.createAnonCommandPrompt());

return container;
}
}

class DestinationLink {
constructor(rawLinkData) {
this.pageNo = rawLinkData[0];
this.nextLinkIndex = rawLinkData[1];
}

get pageCaption() {
return pageCaptions[this.pageNo];
}

createLinkElement(caption) {
var link = document.createElement("a");

link.href = "/?s=6&p=" + zeroPad(this.pageNo);
link.hash = this.nextLinkIndex;
link.title = caption;

return link;
}
}

function createLink(linkData) {
if (linkData.nextPages.length == 0) {
return linkData.createCommandPrompt(linkData.name);
}

var container = document.createElement("div");

while (linkData.nextPages.length > 0) {
var destinationLink = linkData.nextPages.pop();
var nextPageCaption = linkData.name;

var innerContainer = linkData.createCommandPrompt(nextPageCaption);

var link = destinationLink.createLinkElement(nextPageCaption);

if ((document.location.pathname == "/trickster.php") && (destinationLink.pageCaption.indexOf("==>") != -1)) {
// In trickster section, replace "==>" in page name with sucker image
link.innerHTML = destinationLink.pageCaption.replace("==>", "");

var sucker = document.createElement("img");
sucker.src = "http://mspaintadventures.com/images/trickster_sitegraphics/sucker.gif";
sucker.style.backgroundColor = linkData.colour;
sucker.style.boxShadow = "0px 0px 2px 2px " + linkData.colour;

link.appendChild(sucker);
} else if (linkData.name.indexOf("English") != -1) {
// Give Lord English, Jack English colourful links
link.appendChild(lordEnglishText(destinationLink.pageCaption));
} else {
link.innerText = destinationLink.pageCaption;
}

link.style.color = linkData.colour;
innerContainer.appendChild(link);

container.appendChild(innerContainer);
}

return container;
}

0 comments on commit 7826ff2

Please sign in to comment.