Skip to content

Commit

Permalink
Add Javascript LinkData class
Browse files Browse the repository at this point in the history
  • Loading branch information
madman-bob committed Sep 14, 2017
1 parent b9c1242 commit 908f6d6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
10 changes: 5 additions & 5 deletions POV Cam/injection.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,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
37 changes: 21 additions & 16 deletions POV Cam/next-page-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ function zeroPad(pageNo) {
return ("00" + pageNo).slice(-6);
}

function createLink(link) {
var name = peoplenames[link[0]];
var colour = colours[link[1]];
var image = images[link[2]];
var nextPages = link[4];
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];
}
}

function createLink(linkData) {
var container = document.createElement("div");

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

var enterCommand = document.createElement("span");
Expand All @@ -26,19 +31,19 @@ function createLink(link) {
return container;
}

while (nextPages.length > 0) {
var nextPage = nextPages.pop();
while (linkData.nextPages.length > 0) {
var nextPage = linkData.nextPages.pop();
var nextPageNo = nextPage[0];
var nextPageIndex = nextPage[1];
var nextPageCaption = name;
var nextPageCaption = linkData.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.src = chrome.extension.getURL("images/" + linkData.image);
personIcon.width = 32;
personIcon.height = 32;
personIcon.style["vertical-align"] = "middle";
Expand All @@ -60,18 +65,18 @@ function createLink(link) {

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;
sucker.style.backgroundColor = linkData.colour;
sucker.style.boxShadow = "0px 0px 2px 2px " + linkData.colour;

link.appendChild(sucker);
} else if (name.indexOf("English") != -1) {
} else if (linkData.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;
link.style.color = linkData.colour;
innerContainer.appendChild(link);

container.appendChild(innerContainer);
Expand Down

0 comments on commit 908f6d6

Please sign in to comment.