GameCATs Highlighting

Highlights stuff, I dunno.

当前为 2014-05-15 提交的版本,查看 最新版本

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