Scrying Workshop Reworked

UX Improvements for Flight Rising's Scrying Workshop and Search

  1. // ==UserScript==
  2. // @name Scrying Workshop Reworked
  3. // @namespace http://www.flightrising.com/
  4. // @description UX Improvements for Flight Rising's Scrying Workshop and Search
  5. // @include http://flightrising.com/main.php?p=scrying&view=*
  6. // @include https://flightrising.com/main.php?p=scrying&view=*
  7. // @include http://flightrising.com/main.php?*&tab=dragon*
  8. // @include https://flightrising.com/main.php?*&tab=dragon*
  9. // @include http://flightrising.com/main.php?dragon=*
  10. // @include https://flightrising.com/main.php?dragon=*
  11. // @include http://flightrising.com/main.php?p=search&search=dragon
  12. // @include https://flightrising.com/main.php?p=search&search=dragon
  13. // @version 1.16
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17.  
  18. var theColors = ["none", "Maize", "White", "Ice", "Platinum", "Silver", "Grey", "Charcoal", "Coal", "Black", "Obsidian", "Midnight", "Shadow", "Mulberry", "Thistle", "Lavender", "Purple", "Violet", "Royal", "Storm", "Navy", "Blue", "Splash", "Sky", "Stonewash", "Steel", "Denim", "Azure", "Caribbean", "Teal", "Aqua", "Seafoam", "Jade", "Emerald", "Jungle", "Forest", "Swamp", "Avocado", "Green", "Leaf", "Spring", "Goldenrod", "Lemon", "Banana", "Ivory", "Gold", "Sunshine", "Orange", "Fire", "Tangerine", "Sand", "Beige", "Stone", "Slate", "Soil", "Brown", "Chocolate", "Rust", "Tomato", "Crimson", "Blood", "Maroon", "Red", "Carmine", "Coral", "Magenta", "Pink", "Rose"];
  19. var theGenders = ["Male","Female"];
  20. var theBreeds = ["None", "Fae", "Guardian", "Mirror", "Pearlcatcher", "Ridgeback", "Tundra", "Spiral", "Imperial", "Snapper", "Wildclaw", "Nocturne", "Coatl", "Skydancer"];
  21. var primaryGenes = ["Basic", "Iridescent", "Tiger", "Clown", "Speckle", "Ripple", "Bar", "Crystal", "Vipera", "Piebald", "Cherub", "Poison"];
  22. var secondaryGenes = ["Basic", "Shimmer", "Stripes", "Eye Spots", "Freckle", "Seraph", "Current", "Daub", "Facet", "Hypnotic", "Paint", "Peregrine", "Toxin"];
  23. var tertiaryGenes = ["Basic", "Circuit", "Unknown 2", "Unknown 3", "Gembond", "Underbelly", "Crackle", "Smoke", "Spines", "Okapi", "Glimmer"];
  24. var theElements = ["None", "Earth", "Plague", "Wind", "Water", "Lightning", "Ice", "Shadow", "Light", "Arcane","Nature", "Fire"];
  25. function privateEye() {
  26. $('select[name="breed"]').attr('id','breed');
  27. $('select[name="gender"]').attr('id','gender');
  28. $('select[name="pc"]').attr('id','bodycolor');
  29. $('select[name="sc"]').attr('id','wingcolor');
  30. $('select[name="tc"]').attr('id','tertcolor');
  31. $('select[name="pg"]').attr('id','prigene');
  32. $('select[name="sg"]').attr('id','secgene');
  33. $('select[name="tg"]').attr('id','tertgene');
  34. $('form:first-of-type').after('<div id="results" style="margin-top: 1em;"></div>');
  35. var theURL = $('form:first-of-type').attr('action');
  36. $('.mb_button').after('<input type="button" value="Reset" style="background-color:#731d08; color:#fff; border:1px solid #000; height:25px; width:130px; font-weight:bold; margin-left: 1em; margin-right: 2em;" class="mb_button" onclick="wipeIt();">').parent('div').after('<div style="position: relative; left: 195px; top: -2.25em; display: inline;"><input type="checkbox" name="hideGone" id="hideGone" value="hideGone">Hide Exalted</div>');
  37. function prettyIt(stuff) {
  38. var resultData = $($.parseHTML(stuff)).find("#super-container").children('div').toArray();
  39. $('#results').html(resultData[2]);
  40. $('#results a[href*="did"]').attr('target','_blank');
  41. $('#results>div:first-of-type>div:first-of-type').attr('style','font-size:12px; text-align:center').css('margin-bottom','.5em');
  42. $('#results>div:first-of-type>div:nth-of-type(2)').attr('style','font-size:12px; text-align:center; line-height:1.5em; margin-bottom:.25em;');
  43. $('#results>div:first-of-type>div:nth-of-type(2)>span:first-of-type').hide();
  44. $('#results>div:first-of-type>div:nth-of-type(2)>span:nth-of-type(2)').attr('id','pages');
  45. if ($('#results>div:first-of-type>div:first-of-type>span:nth-of-type(2)').text() > 20) {
  46. $('#pages').css('float','none');
  47. $('#pages').html(function () {
  48. return $(this).html().replace('Page ', '');
  49. });
  50. if($('a:contains("»")').length) {
  51. $('a:contains("»")').html('<img src="/images/layout/arrow_right.png" style="vertical-align:middle; margin-left: 1em;"/>');
  52. } else {
  53. $('#pages').append('<img src="/images/layout/arrow_right_off.png" style="vertical-align:middle; margin-left: 1em;"/>');
  54. }
  55. if($('a:contains("«")').length) {
  56. $('a:contains("«")').html('<img src="/images/layout/arrow_left.png" style="vertical-align:middle; margin-right: 1em;"/>');
  57. } else {
  58. $('#pages').prepend('<img src="/images/layout/arrow_left_off.png" style="vertical-align:middle; margin-right: 1em;"/>');
  59. }
  60. }
  61. $('#pages').clone().attr('id','pages2').appendTo( "#results>div" );
  62. $('#pages2').css('font-size','12px').css('width','100%').css('text-align','center').css('margin-top','-1em');
  63. $('#results img[src*="avatar"]').parent('a').each(function() {
  64. var theID = (/did=(\d+)/.exec($(this).attr('href')))[1];
  65. $(this).attr('rel','includes/ah_dragonajax.php?id='+theID);
  66. $(this).cluetip({
  67. height: 380,
  68. ajaxCache: true,
  69. onShow: function (ct, ci) {
  70. var thePicture = '<img src="rendern/350/' + (parseInt(10*(theID/1000))+1) + '/' + theID + '_350.png" width="265px">';
  71. $('#cluetip div[style*="color:#999"]').html(thePicture);
  72. }
  73. });
  74. });
  75. exaltBeGone();
  76. }
  77. function exaltBeGone() {
  78. if ($('#hideGone').is(':checked')) {
  79. $('#results img[src*="avatar"]').parent('a').parent('span').parent('span:contains("Exalted")').hide();
  80. if($('#results img[src*="avatar"]').parent('a').parent('span').parent('span').length-$('#results img[src*="avatar"]').parent('a').parent('span').parent('span:contains("Exalted")').length<1) {
  81. $('#pages2').hide();
  82. }
  83. } else {
  84. $('#results img[src*="avatar"]').parent('a').parent('span').parent('span:contains("Exalted")').show();
  85. $('#pages2').show();
  86. }
  87. }
  88. $('#hideGone').change( function () {
  89. exaltBeGone();
  90. });
  91. $('form:first-of-type').submit(function (e) {
  92. e.preventDefault();
  93. $('#results').html('<center><br><br>Searching...<br><br><img src="/images/layout/loading.gif"></center>');
  94. $.ajax({
  95. type: "POST",
  96. data: $('form').serialize(),
  97. url: theURL,
  98. cache:false
  99. }).done(function(stuff){
  100. prettyIt(stuff);
  101. });
  102. });
  103. this.sPage = function (page) {
  104. $("#newpage").val(page);
  105. var newData = $('form').serialize();
  106. var newURL = $('#searched').attr('action');
  107. $('#results').html('<center><br><br>Loading...<br><br><img src="/images/layout/loading.gif"></center>');
  108. $.ajax({
  109. type: "POST",
  110. data: newData,
  111. url: newURL,
  112. cache:false
  113. }).done(function(stuff){
  114. prettyIt(stuff);
  115. });
  116. }
  117. this.wipeIt = function () {
  118. $('form')[0].reset();
  119. $('#results').html('');
  120. }
  121. }
  122. function changingRoom() {
  123. $( document ).on( "click", "#scry", function() {
  124. var theDragon = parseInt((/did=(\d+)/.exec(window.location.href) || /dragon=(\d+)/.exec(window.location.href))[1]);
  125. localStorage.setItem('scrying_greenranger',theDragon);
  126. movinRightAlong('morphintime');
  127. });
  128. }
  129.  
  130. function showMeYourTrueColors(theSource) {
  131. // then, put together the translations
  132. var dragonInfo = parseQueryString(theSource);
  133. var breed = theBreeds[parseInt(dragonInfo["style"])] + "</font></b><hr>";
  134. var gender = "|<b><font color=#731d08>" + theGenders[parseInt(dragonInfo["gender"])];
  135. var primary = "<b>Primary Gene:</b> " + theColors[parseInt(dragonInfo["body"])] + " " + primaryGenes[parseInt(dragonInfo["prig"])];
  136. var secondary = "<b>Secondary Gene:</b> " + theColors[parseInt(dragonInfo["wing"])] + " " + secondaryGenes[parseInt(dragonInfo["secg"])];
  137. var tertiary = "<b>Tertiary Gene:</b> " + theColors[parseInt(dragonInfo["tert"])] + " " + tertiaryGenes[parseInt(dragonInfo["tertg"])];
  138.  
  139. // then, assign the translations to the rel
  140. return gender + ' ' + breed + '|' + primary + '|' + secondary + '|' + tertiary;
  141. }
  142.  
  143. function metaMorph() {
  144. var theRound = 0;
  145. this.lolRedNinjaRanger = function() {
  146. if($('#greenranger').val() && theRound === 0){
  147. theRound = 1;
  148. // $('#summon_dragon').click();
  149. setTimeout( "$('#summon_dragon').click();",250 );
  150. } else if($("#breed").val()&&$("#gender").val()&&$("#setage").val()&&$("#prigene").val()&&$("#bodycolor").val()&&$("#secgene").val()&&$("#wingcolor").val()&&$("#tertgene").val()&&$("#tertcolor").val()&&$("#element").val()) {
  151. lolRedRanger();
  152. } else {
  153. alert('oops');
  154. $('#newdragon').html("");
  155. }
  156. $(document).ajaxSuccess(function(e, xhr, options) {
  157. if (options.url.indexOf('getstats') > -1 ) {
  158. // alert('round: '+theRound);
  159. if (theRound == 1 && $('#setage').val() == 0) {
  160. // alert('ok');
  161. $('#setage').val(1).attr('selected','selected');
  162. theRound = 2;
  163. lolRedRanger();
  164. }
  165. }
  166. });
  167. }
  168. this.runAway = function() {
  169. $("#makindragons")[0].reset();
  170. $('#searcher').css('display','none');
  171. $("#newdragon").html("");
  172. }
  173. this.cowsWithHats = function() {
  174. $("select").each(function() {
  175. var theOptions = $(this).find("option"),
  176. random = ~~(Math.random() * theOptions.length);
  177. theOptions.eq(random).prop("selected", true);
  178. });
  179. lolRedRanger();
  180. $('#searcher').css('display','block');
  181. }
  182.  
  183. this.canWeFixIt = function() {
  184. $('select').attr('onChange','lolRedNinjaRanger()');
  185. $('#bodycolor').insertBefore($('span:contains("Primary Gene")'));
  186. $('#bodycolor').before($('span:contains("Primary Color")')).before(' ');
  187. $('#wingcolor').insertBefore($('span:contains("Secondary Gene")'));
  188. $('#wingcolor').before($('span:contains("Secondary Color")')).before(' ');
  189. $('#tertcolor').insertBefore($('span:contains("Tertiary Gene")'));
  190. $('#tertcolor').before($('span:contains("Tertiary Color")')).before(' ');
  191. $('#makindragons br').remove();
  192. $('select').after('<br>');
  193. $('#makindragons').attr('style','position: relative; top:15px;');
  194. $('#makindragons .thingbutton').css('display','none');
  195. $('#element').after('<br/><input class="beigebutton thingbutton" type="button" onclick="movinRightAlong(\'dragon\')" value="Search?" id="searcher" style="position: relative; top: .8em; padding: 0px 20px; margin: 5px 45px 0; width: 120px;">').after('<br/><input class="beigebutton thingbutton" type="button" onclick="runAway()" value="Reset" style="position: relative; top: .5em; padding: 0px 20px; margin: 5px 45px 0; width: 120px;">').after('<br/><input class="beigebutton thingbutton" type="button" onclick="cowsWithHats()" value="Random" style="position: relative; top: .3em; padding: 0px 20px; margin: 5px 45px 0; width: 120px;">');
  196. }
  197. }
  198.  
  199. function picturePicture() {
  200. $( document ).on( "click", "#preview img", function() {
  201. var dragonInfo = parseQueryString($(this).attr('src'));
  202. localStorage.setItem('scrying_breed',parseInt(dragonInfo["style"]));
  203. localStorage.setItem('scrying_gender',parseInt(dragonInfo["gender"]));
  204. localStorage.setItem('scrying_setage',1);
  205. localStorage.setItem('scrying_bodycolor',parseInt(dragonInfo["body"]));
  206. localStorage.setItem('scrying_wingcolor',parseInt(dragonInfo["wing"]));
  207. localStorage.setItem('scrying_tertcolor',parseInt(dragonInfo["tert"]));
  208. localStorage.setItem('scrying_prigene',parseInt(dragonInfo["prig"]));
  209. localStorage.setItem('scrying_secgene',parseInt(dragonInfo["secg"]));
  210. localStorage.setItem('scrying_tertgene',parseInt(dragonInfo["tertg"]));
  211. localStorage.setItem('scrying_element',parseInt(dragonInfo["elem"]));
  212. movinRightAlong('morphintime');
  213. });
  214. $('#id10t1').css('left','10px').css('text-align','right').before('<div id="pic1" style="height: 175px; width: 175px; position: absolute; bottom: 70px; left:-8px;"></div>');
  215. $('#id10t2').css('left','552px').before('<div id="pic2" style="height: 175px; width: 175px; position: absolute; left: 545px; bottom: 70px"></div>');
  216. if ($('div[style*="bg_assaybloodlines"]').length != 0) {
  217. $('#pic1').css('bottom','140px').css('left', '60px');
  218. $('#pic2').css('bottom','140px').css('left', '331px');
  219. }
  220. function showMeNow() {
  221. var id = $(this).attr('id').slice(-1);
  222. if ($(this).val() !== "") {
  223. var theDragon = $(this).val().match(/[^\=]+$/)[0].replace(/\s+/g, "").replace(/\D+/g, "");
  224. $(this).val(theDragon);
  225. if (theDragon) {
  226. var theGroup = (parseInt(10*(theDragon/1000))+1);
  227. $('#pic'+id).html('<a href="main.php?dragon='+theDragon+'"><img id="Dragon'+id+'" src="rendern/350/'+theGroup+'/'+theDragon+'_350.png" width="175px"></a>');
  228. $('#Dragon'+id).error(function(){
  229. $('#id10t'+id).val('');
  230. $('#pic'+id).html('');
  231. });
  232. }
  233. } else {
  234. $('#pic'+id).html('');
  235. $('#check').css('display','none');
  236. }
  237. if ($('#id10t1').val()||$('#id10t2').val()) {
  238. // lower opacity bg
  239. $('img[src*="bg_foreseeprogeny"]').css('opacity','0.4');
  240. } else {
  241. // full opacity bg
  242. $('img[src*="bg_foreseeprogeny"]').css('opacity','1');
  243. }
  244. if($(this).val() === '') {
  245. $('#pic'+id).html('');
  246. $('#check').css('display','none');
  247. }
  248. $('#validity').html('');
  249. $('#symbol').html('');
  250. }
  251. $('input[id*="id10t"]').change(showMeNow);
  252. }
  253.  
  254. function exogamyFTW() {
  255. $('.thingbutton').attr('onclick','hipCheck()');
  256. $('#id10t1').parent('div:first-child').attr('style','vertical-align:middle; width:570px; margin-left:0px; padding-top:100px; text-align: center;').after('<div id="symbol" style="position: relative; font-size: 80px; top: -250px; width: 570px; text-align: center; visibility: hidden;"></div>').after('<div id="validity" style="width:140px; font-size: 12px; text-align: center; margin: 1em auto;"></div>');
  257. this.hipCheck = function() {
  258. $('#symbol').css('visibility','hidden');
  259. var id10t1 = $('#id10t1').val();
  260. var id10t2 = $('#id10t2').val();
  261. $("#validity").html('<img src="/images/layout/loading.gif"> loading...');
  262. $.ajax({
  263. type: "POST",
  264. data: {id1: id10t1, id2: id10t2},
  265. url: "includes/ol/scryer_bloodlines.php",
  266. cache:false
  267. }).done(function(stuff){
  268. var theVerdict = $($.parseHTML(stuff)).toArray();
  269. $("#validity").html($(theVerdict[2]).text().replace('Success!','<h2 style="color:green; margin: -8px auto 2px;">Success!</h2>')).append('<input class="beigebutton thingbutton" style="padding: 5px 20px; margin-top: .75em; left: -3px;" type="button" border="0" onclick="movinRightAlong(\'progeny\')" value="Scry Progeny?">');
  270. if($("#validity").text().indexOf( "Success" ) !== -1) {
  271. $('#symbol').css('color','green').text('✔').css('top','-275px').css('visibility','visible');
  272. } else {
  273. $('#symbol').css('color','red').text('✖').css('top','-290px').css('visibility','visible');
  274. }
  275. });
  276. }
  277. }
  278.  
  279. function theWorks() {
  280. this.movinRightAlong = function(where) {
  281. localStorage.setItem('scrying_destination',where);
  282. localStorage.setItem('scrying_id10t1',$('#id10t1').val());
  283. localStorage.setItem('scrying_id10t2',$('#id10t2').val());
  284. $('select').each(function() {
  285. localStorage.setItem('scrying_'+$(this).attr('id'),$(this).val());
  286. });
  287. if(where === 'bloodlines') {
  288. window.location = "main.php?p=scrying&view=bloodlines";
  289. } else if(where === 'progeny') {
  290. window.location = "main.php?p=scrying&view=progeny";
  291. } else if(where === 'morphintime') {
  292. var win = window.open("main.php?p=scrying&view=morphintime","_blank");
  293. win.focus();
  294. } else if(where === 'dragon') {
  295. var win = window.open("main.php?p=search&search=dragon","_blank");
  296. win.focus();
  297. }
  298. }
  299. this.parseQueryString = function(theString) {
  300. theString = theString.slice(34);
  301. var query = theString,
  302. map = {};
  303. query.replace(/([^&=]+)=?([^&]*)(?:&+|$)/g, function(match, key, value) {
  304. (map[key] = map[key] || []).push(value);
  305. });
  306. return map;
  307. }
  308. }
  309.  
  310. $(document).ajaxSuccess(function(e, xhr, options) {
  311. if (options.url.indexOf('scryer_get') > -1) {
  312. canWeFixIt();
  313. } else if (options.url.indexOf('scryer_progeny') > -1) {
  314. $('#par1').remove();
  315. $('#par2').remove();
  316. $('#preview img').each(function() {
  317. $(this).attr('title',showMeYourTrueColors($(this).attr('src')));
  318. $(this).cluetip({splitTitle: '|', width: 245, height: "auto", cursor: "pointer", positionBy: "fixed", leftOffset: "-10px", topOffset: "95px"});
  319. });
  320. $('#check').css('display','inline');
  321. }
  322. });
  323.  
  324. function InjectScript(func, documentLoaded) {
  325. // Function stolen-I-mean-borrowed from the old FRE script
  326. // If head isn't ready, defer execution (this is Chrome support shenanigans)
  327. var head = document.head || document.getElementsByTagName("head")[0];
  328. if (head) {
  329. var source = func.toString();
  330. var scriptEl = document.createElement('script');
  331. scriptEl.setAttribute("id", func.name);
  332. scriptEl.setAttribute("type", "text/javascript");
  333. if (documentLoaded) {
  334. source = "document.addEventListener('DOMContentLoaded', " + source + ", true);";
  335. } else {
  336. source = "(" + source + ")();";
  337. }
  338. scriptEl.innerHTML = source;
  339. head.appendChild(scriptEl);
  340. }
  341. else {
  342. setTimeout(function() { InjectScript(func, documentLoaded); }, 0);
  343. }
  344. }
  345.  
  346. var thePage = document.location.href.match(/[^\=]+$/)[0];
  347. InjectScript(theWorks);
  348. if (thePage === "dragon") {
  349. InjectScript(privateEye);
  350. } else if (thePage === "bloodlines") {
  351. InjectScript(picturePicture);
  352. InjectScript(exogamyFTW);
  353. } else if (thePage === "progeny") {
  354. InjectScript(picturePicture);
  355. InjectScript(showMeYourTrueColors);
  356. $('input[value="Preview"]').parent('div').css('width','250px').css('text-align','center');
  357. $('input[value="Preview"]').after('<input class="beigebutton thingbutton" type="button" onclick="movinRightAlong(\'bloodlines\')" id="check" style="margin-top: .5em; display: none;" value="Check Bloodlines?">');
  358. } else if (thePage === "morphintime") {
  359. InjectScript(metaMorph);
  360. runAway();
  361. } else {
  362. InjectScript(changingRoom);
  363. $('span[style="position:absolute; bottom:10px; right:110px;"]').css('right','207px');
  364. $('span[style="position:absolute; bottom:10px; right:-10px;"]').css('right','87px');
  365. $('div[style*="390px"]').css('width','320px').parent('span').parent('div').append('<span style="position:absolute; bottom:10px; right:-10px;"><input type="image" id="scry" src="http://i59.tinypic.com/21erkfk.png" value="Scry"></span>');
  366. }
  367.  
  368. var thePage = document.location.href.match(/[^\=]+$/)[0];
  369. if(localStorage.getItem('scrying_destination') === thePage) {
  370. for(var key in localStorage) {
  371. if (key.indexOf("scrying_") > -1) {
  372. $('#'+key.slice(8)).val(localStorage.getItem(key));
  373. localStorage.removeItem(key);
  374. }
  375. }
  376. if(thePage === 'bloodlines') {
  377. $( "#id10t1" ).trigger( "change" );
  378. $( "#id10t2" ).trigger( "change" );
  379. hipCheck();
  380. } else if(thePage === 'progeny') {
  381. $( "#id10t1" ).trigger( "change" );
  382. $( "#id10t2" ).trigger( "change" );
  383. showNewbies();
  384. } else if(thePage === 'morphintime') {
  385. lolRedNinjaRanger();
  386. } else if(thePage === 'dragon') {
  387. $( "form:first" ).submit();
  388. }
  389. }