GameCATs Highlighting

Highlights stuff, I dunno.

当前为 2016-10-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GameCATs Highlighting
  3. // @version 2.0.17
  4. // @author Metallia - Formerly known as King of Cats
  5. // @namespace Cats
  6. // @description Highlights stuff, I dunno.
  7. // @include http://www.gamefaqs.com/*
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_deleteValue
  11. // ==/UserScript==
  12.  
  13. // css guys, look for ".gamecats-highlight" for anything I've added a background colour to, or ".gamecats-text" for text colour changes, or just the "friend" class GameFAQs itself uses for their own highlighting.
  14. // Also, to be more specific:
  15. // .gamecats-highlight-message-tr
  16. // .gamecats-highlight-message-td
  17. // .gamecats-highlight-topic-tr
  18. // .gamecats-highlight-topic-td
  19. // .gamecats-text-tr
  20. // .gamecats-text-td
  21. // .gamecats-text-a
  22. // .gamecats-autocontrast-black
  23. // .gamecats-autocontrast-white
  24.  
  25. // First run check, fill in some settings. Also fill in one list if they try to save with none. >_>
  26. if (!GM_getValue("numberOfLists") || GM_getValue("numberOfLists") == 0) {
  27. GM_setValue("numberOfLists",1);
  28. GM_setValue("useColouredCustomCSS",false);
  29. GM_setValue("caseInsensitive",true);
  30. GM_setValue("styleGroupAsTag",false);
  31. GM_setValue("settingsLinkLocation",2);
  32. GM_setValue("Main Settings","Script Author|Metallia|#B266FF|auto|true,false,true,false,false,true,false,false,false,false,false,false,false,false,false");
  33. GM_setValue("version","2.0.17");
  34. }
  35.  
  36. // Attach a link to the settings page on GameFAQs.
  37. var userInbox = document.getElementsByClassName("user_inbox");
  38. if (userInbox[0] != null) {
  39. if (GM_getValue("settingsLinkLocation","unset") === 0 || GM_getValue("settingsLinkLocation","unset") === 2) {
  40. var settingsLink = document.createElement('a');
  41. settingsLink.setAttribute("href","#HighlightSettings");
  42. settingsLink.addEventListener('click',function() {prepSettings();},true);
  43. settingsLink.textContent = "Highlight Settings";
  44. var userLink = userInbox[0].childNodes;
  45. for (var i = 0; i < userLink.length; i++) {
  46. if ((userLink[i].className||"").indexOf("welcome") != -1) {
  47. userLink[i].parentNode.insertBefore(settingsLink,userLink[i].nextSibling);
  48. userLink[i].parentNode.insertBefore(document.createTextNode(" "),userLink[i].nextSibling);
  49. break;
  50. }
  51. }
  52. }
  53. }
  54. if (document.location.href.match(/(^[^#]*)/)[0] === "http://www.gamefaqs.com/user") {
  55. if (GM_getValue("settingsLinkLocation","unset") === 1 || GM_getValue("settingsLinkLocation","unset") === 2) {
  56. var myAccountTable = document.getElementsByTagName("tbody")[2];
  57. var settingsTR = document.createElement('tr');
  58. var settingsTD = document.createElement('td');
  59. settingsTD.setAttribute("colspan","2");
  60. var settingsLink = document.createElement('a');
  61. settingsLink.setAttribute("href","#HighlightSettings");
  62. settingsLink.addEventListener('click',function() {prepSettings();},true);
  63. settingsLink.textContent = "GameCATs";
  64. myAccountTable.appendChild(settingsTR);
  65. settingsTR.appendChild(settingsTD);
  66. settingsTD.appendChild(settingsLink);
  67. }
  68. }
  69.  
  70. var version = GM_getValue("version").split(".");
  71. var theme = document.getElementsByTagName("body")[0].getAttribute("class");
  72.  
  73. // Settings to get filled in by getSettings()
  74. var storedNumberOfLists = new Array();
  75. var storedListNames = new Array();
  76. var storedUsernames = new Array();
  77. var storedHighlightColours = new Array();
  78. var storedHighlightTextColours = new Array();
  79. var storedActionHighlightTopic = new Array();
  80. var storedActionIgnoreTopic = new Array();
  81. var storedActionHighlightPost = new Array();
  82. var storedActionIgnorePost = new Array();
  83. var storedActionTagTopic = new Array();
  84. var storedActionTagPost = new Array();
  85. var storedActionHighlightTopicContent = new Array();
  86. var storedActionIgnoreTopicContent = new Array();
  87. var storedActionHighlightPostContent = new Array();
  88. var storedActionIgnorePostContent = new Array();
  89. var storedActionAllowStacking = new Array();
  90. var storedActionHighlightAdmin = new Array();
  91. var storedActionHighlightMod = new Array();
  92. var storedActionHighlightVIP = new Array();
  93. var storedActionHighlightTC = new Array();
  94. var storedCaseInsensitive = new Array();
  95. var storedUseColouredCustomCSSSetting = new Array();
  96. var storedStyleGroupAsTagSetting = new Array();
  97.  
  98. // Highlight functions
  99.  
  100. function compareVersion (testVersion,exact) {
  101. testVersion = testVersion.split(".");
  102. if (exact) {
  103. return ((testVersion[0] == version[0]) && (testVersion[1] == version[1]) && (testVersion[2] == version[2]));
  104. } else {
  105. if (version[0] < testVersion[0]) {
  106. return true;
  107. } else if (version[0] == testVersion[0]) {
  108. if (version[1] < testVersion[1]) {
  109. return true;
  110. } else if (version[1] == testVersion[1]) {
  111. if (version[2] < testVersion[2]) {
  112. return true;
  113. } else {
  114. return false;
  115. }
  116. } else {
  117. return false;
  118. }
  119. } else {
  120. return false;
  121. }
  122. }
  123. }
  124.  
  125. function getSettings () {
  126. storedNumberOfLists = GM_getValue("numberOfLists");
  127. var allOfTheThings = GM_getValue("Main Settings");
  128. var fullList = allOfTheThings.split("^");
  129. var splitListItems = new Array();
  130. var usernames = new Array();
  131. var splitActions = new Array();
  132. for (var i = 0; i < storedNumberOfLists; i++) {
  133. splitListItems = fullList[i].split("|");
  134. splitActions[i] = splitListItems[4].split(",");
  135. storedListNames[i] = splitListItems[0];
  136. storedUsernames[i] = splitListItems[1].split(",");
  137. storedHighlightColours[i] = splitListItems[2];
  138. storedHighlightTextColours[i] = splitListItems[3];
  139. // These look kinda funky, but I'm trading in the stored "true" and "false" strings for actual booleans.
  140. storedActionHighlightTopic[i] = (splitActions[i][0] == "true");
  141. storedActionIgnoreTopic[i] = (splitActions[i][1] == "true");
  142. storedActionHighlightPost[i] = (splitActions[i][2] == "true");
  143. storedActionIgnorePost[i] = (splitActions[i][3] == "true");
  144. storedActionTagTopic[i] = (splitActions[i][4] == "true");
  145. storedActionTagPost[i] = (splitActions[i][5] == "true");
  146. storedActionHighlightTopicContent[i] = (splitActions[i][6] == "true");
  147. storedActionIgnoreTopicContent[i] = (splitActions[i][7] == "true");
  148. storedActionHighlightPostContent[i] = (splitActions[i][8] == "true");
  149. storedActionIgnorePostContent[i] = (splitActions[i][9] == "true");
  150. storedActionAllowStacking[i] = (splitActions[i][10] == "true");
  151. storedActionHighlightAdmin[i] = (splitActions[i][11] == "true");
  152. storedActionHighlightMod[i] = (splitActions[i][12] == "true");
  153. storedActionHighlightVIP[i] = (splitActions[i][13] == "true");
  154. storedActionHighlightTC[i] = (splitActions[i][14] == "true");
  155. }
  156. storedCaseInsensitive = GM_getValue("caseInsensitive");
  157. storedUseColouredCustomCSSSetting = GM_getValue("useColouredCustomCSS");
  158. storedStyleGroupAsTagSetting = GM_getValue("styleGroupAsTag");
  159. }
  160.  
  161. if (compareVersion("0.8.0")) {
  162. GM_deleteValue("useChromeSettings");
  163. }
  164. if (compareVersion("0.9.0")) {
  165. GM_deleteValue("respectTags");
  166. }
  167. if (compareVersion("1.2.3")) {
  168. GM_setValue("settingsLinkLocation",2);
  169. }
  170.  
  171. getSettings();
  172.  
  173. GM_setValue("version","2.0.17");
  174.  
  175. // The settings page save button and right click menu prime the data for storage first, then recall this function with a new origin to actually store it.
  176. function saveSettings (origin,username,listIndex,addOrRemove) {
  177. var smashedUsernames;
  178. var smashedActions;
  179. var smashedFullList = new Array();
  180. var smashedAllOfTheThings = new Array();
  181. if (origin == "import") {
  182. var importField = document.getElementById("exportImportField");
  183. var importString = importField.value;
  184. if (importString.split("|").length <= 3) {
  185. if (!confirm("This data seems malformed and may break your settings.\nImport data anyway?")) {
  186. throw "Abort settings import.";
  187. }
  188. }
  189. GM_setValue("Main Settings",importString);
  190. GM_setValue("numberOfLists",importString.split("^").length);
  191. }
  192. if (origin == "internal") {
  193. for (var i = 0; i < storedNumberOfLists; i++) {
  194. smashedUsernames = storedUsernames[i].join(",");
  195. smashedActions = storedActionHighlightTopic[i]+","+storedActionIgnoreTopic[i]+","+storedActionHighlightPost[i]+","+storedActionIgnorePost[i]+","+storedActionTagTopic[i]+","+storedActionTagPost[i]+","+storedActionHighlightTopicContent[i]+","+storedActionIgnoreTopicContent[i]+","+storedActionHighlightPostContent[i]+","+storedActionIgnorePostContent[i]+","+storedActionAllowStacking[i]+","+storedActionHighlightAdmin[i]+","+storedActionHighlightMod[i]+","+storedActionHighlightVIP[i]+","+storedActionHighlightTC[i];
  196. smashedFullList[i] = storedListNames[i]+"|"+smashedUsernames+"|"+storedHighlightColours[i]+"|"+storedHighlightTextColours[i]+"|"+smashedActions;
  197. }
  198. smashedAllOfTheThings = smashedFullList.join("^");
  199. GM_setValue("Main Settings",smashedAllOfTheThings);
  200. var importField = document.getElementById("exportImportField");
  201. if (importField){
  202. importField.setAttribute('value',smashedAllOfTheThings);
  203. }
  204. }
  205. if (origin == "rightclickmenu") {
  206. if (addOrRemove == "add") {
  207. storedUsernames[listIndex][storedUsernames[listIndex].length] = username;
  208. }
  209. if (addOrRemove == "remove") {
  210. storedUsernames[listIndex].splice(storedUsernames[listIndex].indexOf(username),1);
  211. }
  212. saveSettings("internal");
  213. }
  214. if (origin == "settingspage") {
  215. var lists = document.evaluate('//div', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  216. var actionLists = document.evaluate('//input[@type="checkbox"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  217. var realLists = 0;
  218. for (var i = 0; i < lists.snapshotLength; i++) {
  219. if (lists.snapshotItem(i).getAttribute("class") !== "container") {
  220. continue; // Fuck you, Chrome >_>
  221. }
  222. storedListNames[realLists] = lists.snapshotItem(i).getElementsByClassName("listnameFields")[0].value;
  223. storedHighlightColours[realLists] = lists.snapshotItem(i).getElementsByClassName("colourFields")[0].value;
  224. storedHighlightTextColours[realLists] = lists.snapshotItem(i).getElementsByClassName("textColourFields")[0].value;
  225. storedUsernames[realLists] = lists.snapshotItem(i).getElementsByClassName("usernameFields")[0].value.replace(/, /g,",").split(",");
  226. storedActionHighlightTopic[realLists] = actionLists.snapshotItem(realLists*15).checked;
  227. storedActionIgnoreTopic[realLists] = actionLists.snapshotItem(realLists*15+1).checked;
  228. storedActionHighlightPost[realLists] = actionLists.snapshotItem(realLists*15+2).checked;
  229. storedActionIgnorePost[realLists] = actionLists.snapshotItem(realLists*15+3).checked;
  230. storedActionTagTopic[realLists] = actionLists.snapshotItem(realLists*15+4).checked;
  231. storedActionTagPost[realLists] = actionLists.snapshotItem(realLists*15+5).checked;
  232. storedActionHighlightTopicContent[realLists] = actionLists.snapshotItem(realLists*15+6).checked;
  233. storedActionIgnoreTopicContent[realLists] = actionLists.snapshotItem(realLists*15+7).checked;
  234. storedActionHighlightPostContent[realLists] = actionLists.snapshotItem(realLists*15+8).checked;
  235. storedActionIgnorePostContent[realLists] = actionLists.snapshotItem(realLists*15+9).checked;
  236. storedActionAllowStacking[realLists] = actionLists.snapshotItem(realLists*15+10).checked;
  237. storedActionHighlightAdmin[realLists] = actionLists.snapshotItem(realLists*15+11).checked;
  238. storedActionHighlightMod[realLists] = actionLists.snapshotItem(realLists*15+12).checked;
  239. storedActionHighlightVIP[realLists] = actionLists.snapshotItem(realLists*15+13).checked;
  240. storedActionHighlightTC[realLists] = actionLists.snapshotItem(realLists*15+14).checked;
  241. realLists++;
  242. }
  243. GM_setValue("numberOfLists",realLists);
  244. // Straggler settings not part of a loop
  245. GM_setValue("caseInsensitive",document.getElementById("caseInsensitiveToggle").checked);
  246. GM_setValue("useColouredCustomCSS",document.getElementById("customCSSToggle").checked);
  247. GM_setValue("settingsLinkLocation",parseInt(document.getElementById("settingsLinkLocation").value));
  248. GM_setValue("styleGroupAsTag",document.getElementById("styleGroupAsTagToggle").checked);
  249. saveSettings("internal");
  250. }
  251. }
  252.  
  253. function makeInsensitive (voodoo) {
  254. if (storedCaseInsensitive) {
  255. return voodoo.toLowerCase();
  256. } else {
  257. return voodoo;
  258. }
  259. }
  260.  
  261. // Always returns in rgba, prefilling an alpha of '1' if none was present.
  262. // Accepts #RRGGBB, rgba(r,g,b,a), or rgb(r,g,b).
  263. function decimalColour (colour, returnAs) {
  264. // The usual #RRGGBB you expect to deal with from user input.
  265. if (colour.substring(0,1) == "#") {
  266. if (returnAs === "style") {
  267. return ("rgba("+parseInt(colour.substring(1,3),16)+","+parseInt(colour.substring(3,5),16)+","+parseInt(colour.substring(5,7),16)+",1)");
  268. } else if (returnAs === "testvalue") {
  269. return true;
  270. } else {
  271. return [parseInt(colour.substring(1,3),16),parseInt(colour.substring(3,5),16),parseInt(colour.substring(5,7),16),1];
  272. }
  273. } else {
  274. // And now for when rgba(r,g,b,a) and rgb(r,g,b) decide to show up, like when pulling the colour directly out of the DOM. >_>
  275. if (colour.substring(0,4) == "rgba") {
  276. var numbersOnly = colour.substring(5,colour.length-1).replace(/, /g,",").split(",");
  277. if (returnAs === "style") {
  278. return ("rgba("+numbersOnly[0]+","+numbersOnly[1]+","+numbersOnly[2]+","+numbersOnly[3]+")");
  279. } else if (returnAs === "testvalue") {
  280. return true;
  281. } else {
  282. return numbersOnly;
  283. }
  284. } else if (colour.substring(0,4) == "rgb(") {
  285. var numbersOnly = colour.substring(4,colour.length-1).replace(/, /g,",").split(",");
  286. if (returnAs === "style") {
  287. return ("rgba("+numbersOnly[0]+","+numbersOnly[1]+","+numbersOnly[2]+",1)");
  288. } else if (returnAs === "testvalue") {
  289. return true;
  290. } else {
  291. numbersOnly[3] = 1;
  292. return numbersOnly;
  293. }
  294. } else if (returnAs === "testvalue") {
  295. return false;
  296. }
  297. }
  298. }
  299.  
  300. function autoContrast (pageType,colour,usernameNode) {
  301. var backgroundColour = decimalColour(colour);
  302. if (!decimalColour(colour,"testvalue")) {
  303. return false;
  304. }
  305. //todo: Check new site colours, update switch values. These are probably wrong.
  306. switch (theme) {
  307. case "red": var themeColour = decimalColour("#7E2525"); break;
  308. case "green": var themeColour = decimalColour("#669E2E"); break;
  309. case "orange": var themeColour = decimalColour("#834121"); break;
  310. case "purple": var themeColour = decimalColour("#330066"); break;
  311. case "cloudy": var themeColour = decimalColour("#192457"); break;
  312. case "sepia": var themeColour = decimalColour("#6C4013"); break;
  313. case "dark-blue": var themeColour = decimalColour("#A1AFF7"); break;
  314. case "dark-red": var themeColour = decimalColour("#F9B8B8"); break;
  315. case "dark-green": var themeColour = decimalColour("#CCF7A1"); break;
  316. case "dark-orange": var themeColour = decimalColour("#FFCCB3"); break;
  317. case "dark-purple": var themeColour = decimalColour("#E5CCFF"); break;
  318. case "grayscale": var themeColour = decimalColour("#404040"); break;
  319. case "cottoncandy": var themeColour = decimalColour("#FF0000"); break;
  320. default: var themeColour = decimalColour("#3449B2");
  321. }
  322. if (storedUseColouredCustomCSSSetting) {
  323. themeColour = decimalColour(window.getComputedStyle(usernameNode).getPropertyValue("color"));
  324. }
  325. // http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html
  326. // http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
  327. var lumiCustom = (0.2126*backgroundColour[0] + 0.7152*backgroundColour[1] + 0.0722*backgroundColour[2])/256;
  328. var lumiDefault =(0.2126*themeColour[0] + 0.7152*themeColour[1] + 0.0722*themeColour[2])/256;
  329. if (lumiCustom >= lumiDefault) {
  330. var contrastRatio = (lumiCustom + 0.05) / (lumiDefault + 0.05);
  331. } else {
  332. var contrastRatio = (lumiDefault + 0.05) / (lumiCustom + 0.05);
  333. }
  334. // If the contrast is awful, we need to replace the text colour.
  335. var themeBrightness = ((themeColour[0]*299) + (themeColour[1]*587) + (themeColour[2]*114)) / 255000;
  336. if ((contrastRatio <= 3.5) || ((contrastRatio > 3.5) && (lumiCustom <= 0.03) && (themeBrightness <= 0.5))) {
  337. // http://stackoverflow.com/a/9664560
  338. var brightness = ((backgroundColour[0]*299) + (backgroundColour[1]*587) + (backgroundColour[2]*114)) / 255000;
  339. // First return is "do we even need to attach styles to text?", second is link colour, and third is plain text.
  340. // I make links "brighter" than the plain text it's next to using the alpha channel.
  341. if (brightness >= 0.5) {
  342. return([true,"rgba(0,0,0,0.8)","rgba(0,0,0,1)","gamecats-autocontrast-black"]);
  343. } else {
  344. return([true,"rgba(256,256,256,1)","rgba(256,256,256,0.8)","gamecats-autocontrast-white"]);
  345. }
  346. } else {
  347. return([false]);
  348. }
  349. }
  350.  
  351. function textHighlight (pageType,tr,usernameNode,colour,textColour,currentStyles) {
  352. // Don't do anything if the field was left blank.
  353. if (textColour !== "") {
  354. if (pageType == "messagelist") {
  355. var postInfo = tr.childNodes[0].childNodes[0];
  356. } else {
  357. var postInfo = tr;
  358. }
  359. var plainTextColour = textColour;
  360. var postInfoLinks = postInfo.getElementsByTagName("a");
  361. var postInfoSpans = postInfo.getElementsByTagName("span");
  362. var catchResults = new Array();
  363. // Check for auto and break out early if we decide we don't need it.
  364. if (textColour == "auto" || textColour == "automatic" || textColour == "automagic" ) {
  365. catchResults = autoContrast(pageType,colour,usernameNode);
  366. if (catchResults[0]) {
  367. textColour = catchResults[1];
  368. plainTextColour = catchResults[2];
  369. } else {
  370. return(false);
  371. }
  372. }
  373. postInfo.setAttribute("class",(postInfo.getAttribute("class")||"")+" gamecats-text gamecats-text-tr "+(catchResults[3]||""));
  374. // If people are stacking styles, we need to replace text colours without blowing up the existing CSS.
  375. var isStyled = false;
  376. for (var i = 0; i < currentStyles.length; i++) {
  377. if (currentStyles[i].indexOf(" color:") != -1) {
  378. isStyled = true;
  379. currentStyles[i] = " color:"+plainTextColour+"!important;";
  380. postInfo.setAttribute("style",currentStyles.join(";"));
  381. break;
  382. }
  383. }
  384. // And if there was no text colour already, just toss one on at the end.
  385. if (!isStyled) {
  386. postInfo.setAttribute("style",(postInfo.getAttribute("style")||"")+" color:"+plainTextColour+"!important;");
  387. }
  388. for (var i = 0; i < postInfoLinks.length; i++) {
  389. if ((postInfoLinks[i].parentNode.nodeName != "LI") && (postInfoLinks[i].parentNode.nodeName != "FORM")) {
  390. postInfoLinks[i].setAttribute("class",(postInfoLinks[i].getAttribute("class")||"")+" gamecats-text gamecats-text-a "+(catchResults[3]||""));
  391. postInfoLinks[i].setAttribute("style","color:"+textColour+"!important;");
  392. }
  393. }
  394. for (var i = 0; i < postInfoSpans.length; i++) {
  395. if ((postInfoSpans[i].getAttribute("class")||"").indexOf("tag") == -1) {
  396. postInfoSpans[i].setAttribute("class",(postInfoSpans[i].getAttribute("class")||"")+" gamecats-text gamecats-text-span "+(catchResults[3]||""));
  397. postInfoSpans[i].setAttribute("style","color:"+textColour+"!important;");
  398. }
  399. }
  400. }
  401. }
  402.  
  403. function highlight (mode,pageType,usernameNode,listName,colour,textColour,topicHighlight,topicIgnore,messageHighlight,messageIgnore,topicListName,messageListName,topicContentHighlight,topicContentIgnore,postContentHighlight,postContentIgnore,allowStacking) {
  404. if (decimalColour(colour,"testvalue")) {
  405. var appendType = "background-color:";
  406. } else {
  407. var appendType = "background-image:";
  408. }
  409. if (pageType == "topiclist") {
  410. var tr = usernameNode.parentNode.parentNode;
  411. if (usernameNode.parentNode.nodeName == "SPAN") { // Stickies still don't have spans
  412. tr = tr.parentNode;
  413. }
  414. var td = tr.childNodes;
  415. if (((tr.getAttribute("class").indexOf("gamecats-highlight") == -1) || (allowStacking)) && ((topicHighlight && !topicIgnore) || (mode == "contentMatch" && topicContentHighlight && !topicContentIgnore))) {
  416. var currentStyles = (tr.getAttribute("style")||"").split(";");
  417. var isStyled = false;
  418. if (allowStacking) {
  419. for (var i = 0; i < currentStyles.length; i++) {
  420. if (currentStyles[i].indexOf(appendType) != -1) {
  421. isStyled = true;
  422. currentStyles[i] = appendType+colour+", "+currentStyles[i].substring(17);
  423. tr.setAttribute("style",currentStyles.join(";"));
  424. break;
  425. }
  426. }
  427. }
  428. if (!isStyled) {
  429. tr.setAttribute("style",(tr.getAttribute("style")||"")+appendType+colour+";");
  430. currentStyles = (tr.getAttribute("style")||"").split(";");
  431. }
  432. tr.setAttribute("class",(tr.getAttribute("class")||"")+" friend gamecats-highlight gamecats-highlight-topic-tr")
  433. textHighlight(pageType,tr,usernameNode,colour,textColour,currentStyles);
  434. for (var i = 0; i < td.length; i++) {
  435. td[i].setAttribute("style","background-color: transparent; background-image: none;");
  436. td[i].setAttribute("class",(td[i].getAttribute("class")||"")+" friend gamecats-highlight gamecats-highlight-topic-td")
  437. }
  438. }
  439. if (topicListName) {
  440. if (usernameNode.parentNode.nodeName == "SPAN") { // Stickies don't have spans
  441. var existingList = usernameNode.parentNode.nextSibling;
  442. if (existingList) {
  443. existingList.textContent = " "+listName+existingList.textContent;
  444. } else {
  445. var newList = usernameNode.parentNode.parentNode.appendChild(document.createTextNode(" "+listName));
  446. }
  447. } else {
  448. var existingList = usernameNode.nextSibling;
  449. if (existingList) {
  450. existingList.textContent = " "+listName+existingList.textContent;
  451. } else {
  452. var newList = usernameNode.parentNode.appendChild(document.createTextNode(" "+listName));
  453. }
  454. }
  455.  
  456. }
  457. if (((mode == "usernameMatch" || mode == "tagMatch") && topicIgnore) || (mode == "contentMatch" && topicContentIgnore)) {
  458. tr.parentNode.removeChild(tr);
  459. }
  460. }
  461. if (pageType == "messagelist") {
  462. // Adding group names
  463. if (messageListName) {
  464. var existingList = usernameNode.parentNode.nextSibling;
  465. if (!storedStyleGroupAsTagSetting) {
  466. if (existingList) {
  467. existingList.textContent = " "+listName+existingList.textContent;
  468. } else {
  469. var newListSpan = usernameNode.parentNode.parentNode.appendChild(document.createElement("span"));
  470. newListSpan.setAttribute("class","user_info");
  471. var newList = newListSpan.appendChild(document.createTextNode(" "+listName));
  472. }
  473. } else {
  474. var newTagSpan = usernameNode.parentNode.parentNode.appendChild(document.createElement("span"));
  475. var whitespace = usernameNode.parentNode.parentNode.appendChild(document.createTextNode(" "));
  476. newTagSpan.textContent = listName;
  477. newTagSpan.setAttribute("class","tag");
  478. }
  479. }
  480. var tr = usernameNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  481. var div = tr.childNodes[0].childNodes[0];
  482. if ((((tr.getAttribute("class")||"").indexOf("gamecats-highlight") == -1) || (allowStacking)) && (((mode == "usernameMatch" || mode == "tagMatch") && messageHighlight && !messageIgnore) || (mode == "contentMatch" && postContentHighlight && !postContentIgnore))) {
  483. var currentStyles = (div.getAttribute("style")||"").split(";");
  484. var isStyled = false;
  485. if (allowStacking) {
  486. for (var i = 0; i < currentStyles.length; i++) {
  487. if (currentStyles[i].indexOf(appendType) != -1) {
  488. isStyled = true;
  489. currentStyles[i] = appendType+colour+", "+currentStyles[i].substring(17);
  490. div.setAttribute("style",currentStyles.join(";"));
  491. break;
  492. }
  493. }
  494. }
  495. if (!isStyled) {
  496. div.setAttribute("style",(div.getAttribute("style")||"")+appendType+colour+";");
  497. currentStyles = (tr.getAttribute("style")||"").split(";");
  498. }
  499. tr.setAttribute("class",(tr.getAttribute("class")||"")+" friend gamecats-highlight gamecats-highlight-message-tr");
  500. div.setAttribute("class",(div.getAttribute("class")||"")+" friend gamecats-highlight gamecats-highlight-message-div");
  501. textHighlight(pageType,tr,usernameNode,colour,textColour,currentStyles);
  502. }
  503. if (((mode == "usernameMatch" || mode == "tagMatch") && messageIgnore) || (mode == "contentMatch" && postContentIgnore)) {
  504. if (tr.parentNode) {
  505. tr.parentNode.removeChild(tr);
  506. }
  507. }
  508. }
  509. }
  510.  
  511. // Finding usernames, looking for tags, etc
  512. var pageType;
  513. var authorTDs;
  514. var titlePostContent;
  515. var userTagsContent;
  516. var topicList = document.evaluate('//table[contains(@class,"board topics tlist newbeta")]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  517. if (topicList !== null) {
  518. authorTDs = document.evaluate('//td[contains(@class,"tauthor")]//a', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  519. pageType = "topiclist";
  520. }
  521.  
  522. var messageList = document.evaluate('//table[contains(@class,"board message")]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  523. if (messageList !== null) {
  524. authorTDs = document.evaluate('//td[contains(@class,"msg")]//a[@class="name menu_toggle"]//b', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  525. pageType = "messagelist";
  526. }
  527.  
  528. if (topicList !== null || messageList !== null) {
  529. for (var k = 0; k < authorTDs.snapshotLength; k++) {
  530. authorTDs.snapshotItem(k).isAdmin = false;
  531. authorTDs.snapshotItem(k).isMod = false;
  532. authorTDs.snapshotItem(k).isVIP = false;
  533. authorTDs.snapshotItem(k).isTC = false;
  534. // Content highlight setup
  535. titlePostContent = authorTDs.snapshotItem(k);
  536. while (titlePostContent.nodeName != "TR") {
  537. titlePostContent = titlePostContent.parentNode;
  538. }
  539. if (pageType == "topiclist") {
  540. titlePostContent = titlePostContent.getElementsByTagName("td")[1].textContent;
  541. } else {
  542. titlePostContent = titlePostContent.childNodes[0].childNodes[1].textContent;
  543. }
  544. // Tag highlight setup
  545. userTagsContent = authorTDs.snapshotItem(k);
  546. if (pageType == "messagelist") {
  547. while (userTagsContent.getAttribute("class") != "msg_infobox") {
  548. userTagsContent = userTagsContent.parentNode;
  549. }
  550. userTagsContent = userTagsContent.getElementsByClassName("user_info")[0];
  551. if (userTagsContent) {
  552. userTagsContent = userTagsContent.textContent;
  553. }
  554. // Make sure we don't forget the first post in a topic, since it doesn't get the (Topic Creator) tag
  555. if ((k == 0) || (k == authorTDs.snapshotLength-1)) {
  556. var anchors = authorTDs.snapshotItem(k).parentNode.parentNode.parentNode.parentNode.getElementsByTagName("a");
  557. if (anchors[0].getAttribute("name") == "1") {
  558. authorTDs.snapshotItem(k).isTC = true;
  559. }
  560. }
  561. } else {
  562. while (userTagsContent.nodeName != "TD") {
  563. userTagsContent = userTagsContent.parentNode;
  564. }
  565. if (userTagsContent.childNodes[1]) {
  566. userTagsContent = userTagsContent.childNodes[1].textContent;
  567. }
  568. }
  569. if (typeof userTagsContent == "string") {
  570. if ((userTagsContent.indexOf("(A)") != -1) || (userTagsContent.indexOf("(Admin)") != -1)) {
  571. authorTDs.snapshotItem(k).isAdmin = true;
  572. }
  573. if ((userTagsContent.indexOf("(M)") != -1) || (userTagsContent.indexOf("(Moderator)") != -1) || (userTagsContent.indexOf("(Lead Moderator)") != -1)) {
  574. authorTDs.snapshotItem(k).isMod = true;
  575. }
  576. if ((userTagsContent.indexOf("(V)") != -1) || (userTagsContent.indexOf("(VIP)") != -1)) { // Not sure if these are the right strings to be looking for, haven't found a VIP to compare against.
  577. authorTDs.snapshotItem(k).isVIP = true;
  578. }
  579. if (userTagsContent.indexOf("(Topic Creator)") != -1) {
  580. authorTDs.snapshotItem(k).isTC = true;
  581. }
  582. }
  583. // Normal stuff
  584. for (var i = 0; i < storedNumberOfLists; i++) {
  585. for (var j = 0; j < storedUsernames[i].length; j++) {
  586. // Standard username match check
  587. if ((pageType == "topiclist" && (storedActionHighlightTopic[i] || storedActionIgnoreTopic[i])) || (pageType != "topiclist" && (storedActionHighlightPost[i] || storedActionIgnorePost[i]))) {
  588. if (authorTDs.snapshotItem(k).textContent == storedUsernames[i][j]) {
  589. highlight("usernameMatch",pageType,authorTDs.snapshotItem(k),storedListNames[i],storedHighlightColours[i],storedHighlightTextColours[i],storedActionHighlightTopic[i], storedActionIgnoreTopic[i], storedActionHighlightPost[i], storedActionIgnorePost[i], storedActionTagTopic[i], storedActionTagPost[i], storedActionHighlightTopicContent[i], storedActionIgnoreTopicContent[i], storedActionHighlightPostContent[i], storedActionIgnorePostContent[i], storedActionAllowStacking[i]);
  590. }
  591. }
  592. // Content-based highlighting check
  593. if ((pageType == "topiclist" && (storedActionHighlightTopicContent[i] || storedActionIgnoreTopicContent[i])) || (pageType != "topiclist" && (storedActionHighlightPostContent[i] || storedActionIgnorePostContent[i]))) {
  594. if (makeInsensitive(titlePostContent).indexOf(makeInsensitive(storedUsernames[i][j])) != -1) {
  595. highlight("contentMatch",pageType,authorTDs.snapshotItem(k),storedListNames[i],storedHighlightColours[i],storedHighlightTextColours[i],storedActionHighlightTopic[i], storedActionIgnoreTopic[i], storedActionHighlightPost[i], storedActionIgnorePost[i], storedActionTagTopic[i], storedActionTagPost[i], storedActionHighlightTopicContent[i], storedActionIgnoreTopicContent[i], storedActionHighlightPostContent[i], storedActionIgnorePostContent[i], storedActionAllowStacking[i]);
  596. }
  597. }
  598. // Tag checks, admin, tc, etc.
  599. if ((storedActionHighlightAdmin[i] && authorTDs.snapshotItem(k).isAdmin) || (storedActionHighlightMod[i] && authorTDs.snapshotItem(k).isMod) || (storedActionHighlightVIP[i] && authorTDs.snapshotItem(k).isVIP) || (storedActionHighlightTC[i] && authorTDs.snapshotItem(k).isTC)) {
  600. highlight("tagMatch",pageType,authorTDs.snapshotItem(k),storedListNames[i],storedHighlightColours[i],storedHighlightTextColours[i],storedActionHighlightTopic[i], storedActionIgnoreTopic[i], storedActionHighlightPost[i], storedActionIgnorePost[i], storedActionTagTopic[i], storedActionTagPost[i], storedActionHighlightTopicContent[i], storedActionIgnoreTopicContent[i], storedActionHighlightPostContent[i], storedActionIgnorePostContent[i], storedActionAllowStacking[i]);
  601. }
  602. // Setting up for the right click menu
  603. authorTDs.snapshotItem(k).setAttribute("contextmenu", "gamecats-menu");
  604. authorTDs.snapshotItem(k).addEventListener("contextmenu", readyMenu, false);
  605. }
  606. }
  607. }
  608. }
  609.  
  610. /*******************\
  611. * Right click menu! *
  612. \*******************/
  613.  
  614. function readyMenu (rightClick) {
  615. getSettings();
  616. // Killing old menu entries so the list doesn't pile up or refuse to refresh with new content
  617. var oldMenu = document.getElementById("gamecats-menu");
  618. if (oldMenu) {
  619. oldMenu.parentNode.removeChild(oldMenu);
  620. }
  621. var mainMenu = document.body.appendChild(document.createElement("menu"));
  622. var mainMenuLabel = mainMenu.appendChild(document.createElement("menu"));
  623. mainMenu.setAttribute("id","gamecats-menu");
  624. mainMenu.setAttribute("type","context");
  625. mainMenuLabel.setAttribute("label","GameCATs Highlighting");
  626. var node = rightClick.target;
  627. var clickedUsername = node.textContent;
  628. var menuItems = new Array();
  629. for (var i = 0; i < storedNumberOfLists; i++) {
  630. menuItems[i] = document.createElement("menuitem");
  631. menuItems[i].setAttribute("label",storedListNames[i]);
  632. menuItems[i].setAttribute("type","checkbox");
  633. menuItems[i].setAttribute("value",i);
  634. mainMenuLabel.appendChild(menuItems[i]);
  635. // Check the box if already listed, and use the "remove" option
  636. if (storedUsernames[i].indexOf(clickedUsername) != -1) {
  637. menuItems[i].setAttribute("checked","true");
  638. menuItems[i].addEventListener("click", function() {saveSettings("rightclickmenu",clickedUsername,this.getAttribute("value"),"remove");}, false);
  639. } else {
  640. menuItems[i].addEventListener("click", function() {saveSettings("rightclickmenu",clickedUsername,this.getAttribute("value"),"add");}, false);
  641. }
  642. }
  643. }
  644.  
  645. /*********************************\
  646. * Time to create a settings page! *
  647. \*********************************/
  648.  
  649. function createSettingsPage () {
  650. // Styyyyyle!
  651. var style = document.createElement("style");
  652. style.textContent = '.container { clear:both; } .priorityButtons, .deleteButtons { display: block; } .usernameFields { height: 160px; width: 447px; } span {float: left;} span:nth-child(2) {clear: left;} label.actionLabels:nth-child(2):after {content: "Highlight/Ignore in Topic List\\00000A"; white-space: pre;} label.actionLabels:nth-child(4):after {content: "Highlight/Ignore in Message List\\00000A"; white-space: pre;} label.actionLabels:nth-child(6):after {content: "Add group name in Topic/Message List\\00000A"; white-space: pre;} label.actionLabels:nth-child(8):after {content: "Highlight/Ignore content in Topic List\\00000A"; white-space: pre;} label.actionLabels:nth-child(10):after {content: "Highlight/Ignore content in Message List\\00000A"; white-space: pre;} label.actionLabels:nth-child(11):after {content: "Allow stacking\\00000A"; white-space: pre;} label.actionLabels:nth-child(15):after {content: "Target Admins/Mods/VIPs/TCs\\00000A"; white-space: pre;} label.caseInsensitiveToggle, label.customCSSToggle, label.settingsLinkLocation { clear:both; display: block;} label.caseInsensitiveToggle:after {content: "Ignore case sensitivity on content matches";} label.customCSSToggle:after {content: "Using CSS with custom colours";} label.styleGroupAsTagToggle:after {content: "Style groups as GameFAQs tags";} label.settingsLinkLocation:before {content: "Settings link location: "} .exportImportLabel:before {content: "\\00000A Import/Export: "; white-space: pre;}';
  653. document.getElementsByTagName("head")[0].appendChild(style);
  654. // Creating all the variables I'll need for the upcoming loop.
  655. var body = document.getElementsByTagName("body")[0];
  656. var container = new Array();
  657. var listname = new Array();
  658. var listnameFields = new Array();
  659. var username = new Array();
  660. var usernameFields = new Array();
  661. var colour = new Array();
  662. var colourFields = new Array();
  663. var textColour = new Array();
  664. var textColourFields = new Array();
  665. var action = new Array();
  666. var actionFields = new Array();
  667. var labels = new Array();
  668. var deleteButtons = new Array();
  669. var priorityButtons = new Array();
  670. var spans = new Array();
  671. // Creating a bunch of input fields for each highlight list.
  672. for (var i = 0; i < storedNumberOfLists; i++) {
  673. // Wrap each entry in its own div, for easy location of children and deletion.
  674. container[i] = document.createElement('div');
  675. container[i].setAttribute('id','container'+i);
  676. container[i].setAttribute('class','container');
  677. body.appendChild(container[i]);
  678. // Pairing a few other things in spans for the sake of styling.
  679. spans[i,0] = document.createElement('span');
  680. spans[i,1] = document.createElement('span');
  681. spans[i,2] = document.createElement('span');
  682. spans[i,3] = document.createElement('span');
  683. container[i].appendChild(spans[i,0]);
  684. container[i].appendChild(spans[i,1]);
  685. container[i].appendChild(spans[i,2]);
  686. container[i].appendChild(spans[i,3]);
  687. // List name, for user organizition or if you choose to let the name of said list show next to usernames.
  688. listnameFields[i] = document.createElement('input');
  689. listnameFields[i].setAttribute('type','text');
  690. listnameFields[i].setAttribute('id','listnameFields'+i);
  691. listnameFields[i].setAttribute('class','listnameFields');
  692. listnameFields[i].setAttribute('placeholder','Group Name');
  693. listnameFields[i].setAttribute('value',storedListNames[i]);
  694. spans[i,0].appendChild(listnameFields[i]);
  695. // The colour to change the background to when a username is matched with one on the list.
  696. colourFields[i] = document.createElement('input');
  697. colourFields[i].setAttribute('type','text');
  698. colourFields[i].setAttribute('id','colourFields'+i);
  699. colourFields[i].setAttribute('class','colourFields');
  700. colourFields[i].setAttribute('placeholder','Background Colour');
  701. colourFields[i].setAttribute('value',storedHighlightColours[i]);
  702. spans[i,0].appendChild(colourFields[i]);
  703. // The colour to change text to when a username is matched with one on the list.
  704. textColourFields[i] = document.createElement('input');
  705. textColourFields[i].setAttribute('type','text');
  706. textColourFields[i].setAttribute('id','textColourFields'+i);
  707. textColourFields[i].setAttribute('class','textColourFields');
  708. textColourFields[i].setAttribute('placeholder','Text Colour (optional)');
  709. textColourFields[i].setAttribute('value',storedHighlightTextColours[i]);
  710. spans[i,0].appendChild(textColourFields[i]);
  711. // Username lists.
  712. usernameFields[i] = document.createElement('textarea');
  713. usernameFields[i].textContent = storedUsernames[i].join(",");
  714. usernameFields[i].setAttribute('id','usernameFields'+i);
  715. usernameFields[i].setAttribute('class','usernameFields');
  716. usernameFields[i].setAttribute('placeholder','Usernames and/or post content to match, case sensitive.');
  717. spans[i,1].appendChild(usernameFields[i]);
  718. // Actions to perform when we find a match, or special matching conditions
  719. for (var j = 0; j < 15; j++) {
  720. labels[i*15+j] = document.createElement('label');
  721. labels[i*15+j].setAttribute('class','actionLabels');
  722. actionFields[i*15+j] = document.createElement('input');
  723. actionFields[i*15+j].setAttribute('type','checkbox');
  724. actionFields[i*15+j].setAttribute('id','actionFields'+(i*15+j));
  725. actionFields[i*15+j].setAttribute('class','actionFields');
  726. spans[i,2].appendChild(labels[i*15+j]);
  727. labels[i*15+j].appendChild(actionFields[i*15+j]);
  728. }
  729. // Pre-check the boxes only if the setting is already present.
  730. if (storedActionHighlightTopic[i] === true) {
  731. actionFields[i*15].setAttribute('checked','');
  732. }
  733. if (storedActionIgnoreTopic[i] === true) {
  734. actionFields[i*15+1].setAttribute('checked','');
  735. }
  736. if (storedActionHighlightPost[i] === true) {
  737. actionFields[i*15+2].setAttribute('checked','');
  738. }
  739. if (storedActionIgnorePost[i] === true) {
  740. actionFields[i*15+3].setAttribute('checked','');
  741. }
  742. if (storedActionTagTopic[i] === true) {
  743. actionFields[i*15+4].setAttribute('checked','');
  744. }
  745. if (storedActionTagPost[i] === true) {
  746. actionFields[i*15+5].setAttribute('checked','');
  747. }
  748. if (storedActionHighlightTopicContent[i] === true) {
  749. actionFields[i*15+6].setAttribute('checked','');
  750. }
  751. if (storedActionIgnoreTopicContent[i] === true) {
  752. actionFields[i*15+7].setAttribute('checked','');
  753. }
  754. if (storedActionHighlightPostContent[i] === true) {
  755. actionFields[i*15+8].setAttribute('checked','');
  756. }
  757. if (storedActionIgnorePostContent[i] === true) {
  758. actionFields[i*15+9].setAttribute('checked','');
  759. }
  760. if (storedActionAllowStacking[i] === true) {
  761. actionFields[i*15+10].setAttribute('checked','');
  762. }
  763. if (storedActionHighlightAdmin[i] === true) {
  764. actionFields[i*15+11].setAttribute('checked','');
  765. }
  766. if (storedActionHighlightMod[i] === true) {
  767. actionFields[i*15+12].setAttribute('checked','');
  768. }
  769. if (storedActionHighlightVIP[i] === true) {
  770. actionFields[i*15+13].setAttribute('checked','');
  771. }
  772. if (storedActionHighlightTC[i] === true) {
  773. actionFields[i*15+14].setAttribute('checked','');
  774. }
  775. // Priority buttons, to move this div to the top.
  776. priorityButtons[i] = document.createElement('input');
  777. priorityButtons[i].setAttribute('id','priorityButtons'+i);
  778. priorityButtons[i].setAttribute('class','priorityButtons');
  779. priorityButtons[i].setAttribute('type','button');
  780. priorityButtons[i].setAttribute('value','Send To Top');
  781. priorityButtons[i].addEventListener('click',function() {this.parentNode.parentNode.parentNode.insertBefore(this.parentNode.parentNode,this.parentNode.parentNode.parentNode.childNodes[0]);},true);
  782. spans[i,3].appendChild(priorityButtons[i]);
  783. // Delete buttons, to trash the whole containing div.
  784. deleteButtons[i] = document.createElement('input');
  785. deleteButtons[i].setAttribute('id','deleteButtons'+i);
  786. deleteButtons[i].setAttribute('class','deleteButtons');
  787. deleteButtons[i].setAttribute('type','button');
  788. deleteButtons[i].setAttribute('value','Delete');
  789. deleteButtons[i].addEventListener('click',function() {this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);},true);
  790. spans[i,3].appendChild(deleteButtons[i]);
  791. }
  792. // Done with all the looping junk, now for the ever-important "save settings" and "new list" buttons.
  793. function newList() {
  794. GM_setValue("numberOfLists",GM_getValue("numberOfLists")+1);
  795. GM_setValue("Main Settings",GM_getValue("Main Settings")+"^||||false,false,false,false,false,false,false,false,false,false,false");
  796. // The anchor set here gets watched on page load to automatically reopen the settings page.
  797. window.location.href = window.location.href.split("#")[0]+"#ReloadHighlightSettings";
  798. location.reload();
  799. }
  800. var caseInsensitiveToggle = [document.createElement('label'),document.createElement('input')];
  801. caseInsensitiveToggle[1].setAttribute('type','checkbox');
  802. caseInsensitiveToggle[1].setAttribute('id','caseInsensitiveToggle');
  803. caseInsensitiveToggle[0].setAttribute('class','caseInsensitiveToggle');
  804. caseInsensitiveToggle[1].setAttribute('class','caseInsensitiveToggle');
  805. if (storedCaseInsensitive == true) {
  806. caseInsensitiveToggle[1].setAttribute('checked','');
  807. }
  808. body.appendChild(caseInsensitiveToggle[0]);
  809. caseInsensitiveToggle[0].appendChild(caseInsensitiveToggle[1]);
  810. var customCSSToggle = [document.createElement('label'),document.createElement('input')];
  811. customCSSToggle[1].setAttribute('type','checkbox');
  812. customCSSToggle[1].setAttribute('id','customCSSToggle');
  813. customCSSToggle[0].setAttribute('class','customCSSToggle');
  814. customCSSToggle[1].setAttribute('class','customCSSToggle');
  815. if (storedUseColouredCustomCSSSetting == true) {
  816. customCSSToggle[1].setAttribute('checked','');
  817. }
  818. body.appendChild(customCSSToggle[0]);
  819. customCSSToggle[0].appendChild(customCSSToggle[1]);
  820. var styleGroupAsTagToggle = [document.createElement('label'),document.createElement('input')];
  821. styleGroupAsTagToggle[1].setAttribute('type','checkbox');
  822. styleGroupAsTagToggle[1].setAttribute('id','styleGroupAsTagToggle');
  823. styleGroupAsTagToggle[0].setAttribute('class','styleGroupAsTagToggle');
  824. styleGroupAsTagToggle[1].setAttribute('class','styleGroupAsTagToggle');
  825. if (storedStyleGroupAsTagSetting == true) {
  826. styleGroupAsTagToggle[1].setAttribute('checked','');
  827. }
  828. body.appendChild(styleGroupAsTagToggle[0]);
  829. styleGroupAsTagToggle[0].appendChild(styleGroupAsTagToggle[1]);
  830. var settingsLinkLocationDropdown = [document.createElement('label'),document.createElement('select')];
  831. var settingsLinkOptions = [document.createElement('option'),document.createElement('option'),document.createElement('option')];
  832. settingsLinkLocationDropdown[1].setAttribute('id','settingsLinkLocation');
  833. settingsLinkLocationDropdown[0].setAttribute('class','settingsLinkLocation');
  834. settingsLinkLocationDropdown[1].setAttribute('class','settingsLinkLocation');
  835. settingsLinkOptions[0].setAttribute('id','header');
  836. settingsLinkOptions[0].setAttribute('value',0);
  837. settingsLinkOptions[0].textContent = 'Header';
  838. settingsLinkOptions[1].setAttribute('id','accountSettings');
  839. settingsLinkOptions[1].setAttribute('value',1);
  840. settingsLinkOptions[1].textContent = 'Account Settings';
  841. settingsLinkOptions[2].setAttribute('id','both');
  842. settingsLinkOptions[2].setAttribute('value',2);
  843. settingsLinkOptions[2].textContent = 'Both';
  844. body.appendChild(settingsLinkLocationDropdown[0]);
  845. settingsLinkLocationDropdown[0].appendChild(settingsLinkLocationDropdown[1]);
  846. settingsLinkLocationDropdown[1].appendChild(settingsLinkOptions[0]);
  847. settingsLinkLocationDropdown[1].appendChild(settingsLinkOptions[1]);
  848. settingsLinkLocationDropdown[1].appendChild(settingsLinkOptions[2]);
  849. settingsLinkOptions[GM_getValue("settingsLinkLocation")].selected = true;
  850. var newListButton = document.createElement('input');
  851. newListButton.setAttribute('id','newListButton');
  852. newListButton.setAttribute('class','newListButton');
  853. newListButton.setAttribute('type','button');
  854. newListButton.setAttribute('value','New Highlighting List');
  855. body.appendChild(newListButton);
  856. newListButton.addEventListener('click',newList,true);
  857. var saveSettingsButton = document.createElement('input');
  858. saveSettingsButton.setAttribute('id','saveSettingsButton');
  859. saveSettingsButton.setAttribute('class','saveSettingsButton');
  860. saveSettingsButton.setAttribute('type','button');
  861. saveSettingsButton.setAttribute('value','Save Settings');
  862. body.appendChild(saveSettingsButton);
  863. saveSettingsButton.addEventListener('click',function() {var here = this;saveSettings("settingspage");here.setAttribute("value","Saved!");setTimeout(function(){here.setAttribute("value","Save Settings")},1000);},true);
  864. var exitButton = document.createElement('input');
  865. exitButton.setAttribute('id','exitButton');
  866. exitButton.setAttribute('class','exitButton');
  867. exitButton.setAttribute('type','button');
  868. exitButton.setAttribute('value','Exit');
  869. body.appendChild(exitButton);
  870. exitButton.addEventListener('click',function() {window.scrollTo(0,0); window.location.href = window.location.href.split("#")[0];},true);
  871. var exportImportLabel = document.createElement('label');
  872. exportImportLabel.setAttribute('id','exportImportLabel');
  873. exportImportLabel.setAttribute('class','exportImportLabel');
  874. var exportImportField = document.createElement('input');
  875. exportImportField.setAttribute('id','exportImportField');
  876. exportImportField.setAttribute('class','exportImportField');
  877. exportImportField.setAttribute('type','text');
  878. body.appendChild(exportImportLabel);
  879. exportImportLabel.appendChild(exportImportField);
  880. var importButton = document.createElement('input');
  881. importButton.setAttribute('id','importButton');
  882. importButton.setAttribute('class','importButton');
  883. importButton.setAttribute('type','button');
  884. importButton.setAttribute('value','Import');
  885. body.appendChild(importButton);
  886. importButton.addEventListener('click',function() {var here = this;saveSettings("import");here.setAttribute("value","Imported!");setTimeout(function(){window.location.href = window.location.href.split("#")[0]+"#ReloadHighlightSettings"; location.reload();},300);},true);
  887. if (window.location.href.split("#")[1] == "ReloadHighlightSettings") {
  888. window.location.href = window.location.href.split("#")[0]+"#HighlightSettings";
  889. window.scrollTo(0,document.body.scrollHeight);
  890. }
  891. }
  892.  
  893. function prepSettings () {
  894. var gfaqsBody = document.getElementsByTagName("body")[0];
  895. var gfaqsHead = document.getElementsByTagName("head")[0];
  896. var killMe = gfaqsBody.childNodes;
  897. var killMeToo = gfaqsHead.childNodes;
  898. for (var i = killMe.length-1; i >= 0; i--) {
  899. gfaqsBody.removeChild(killMe[i]);
  900. }
  901. for (var i = killMeToo.length-1; i >= 0; i--) {
  902. gfaqsHead.removeChild(killMeToo[i]);
  903. }
  904. var title = gfaqsHead.appendChild(document.createElement("title"));
  905. title.textContent = "Highlight Settings";
  906. createSettingsPage();
  907. }
  908.  
  909. if (window.location.href.split("#")[1] == "ReloadHighlightSettings") {
  910. prepSettings();
  911. }