GameCATs Highlighting

Highlights stuff, I dunno.

目前为 2015-12-15 提交的版本,查看 最新版本

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