Created
May 8, 2019 09:29
-
-
Save lctseng/f0e56952ada0f8310eb7f219e9db9bc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){ | |
function deepCompare(){var n,e,t,r;function o(n,e){var a;if(isNaN(n)&&isNaN(e)&&"number"==typeof n&&"number"==typeof e)return!0;if(n===e)return!0;if("function"==typeof n&&"function"==typeof e||n instanceof Date&&e instanceof Date||n instanceof RegExp&&e instanceof RegExp||n instanceof String&&e instanceof String||n instanceof Number&&e instanceof Number)return n.toString()===e.toString();if(!(n instanceof Object&&e instanceof Object))return!1;if(n.isPrototypeOf(e)||e.isPrototypeOf(n))return!1;if(n.constructor!==e.constructor)return!1;if(n.prototype!==e.prototype)return!1;if(t.indexOf(n)>-1||r.indexOf(e)>-1)return!1;for(a in e){if(e.hasOwnProperty(a)!==n.hasOwnProperty(a))return!1;if(typeof e[a]!=typeof n[a])return!1}for(a in n){if(e.hasOwnProperty(a)!==n.hasOwnProperty(a))return!1;if(typeof e[a]!=typeof n[a])return!1;switch(typeof n[a]){case"object":case"function":if(t.push(n),r.push(e),!o(n[a],e[a]))return!1;t.pop(),r.pop();break;default:if(n[a]!==e[a])return!1}}return!0}if(arguments.length<1)return!0;for(n=1,e=arguments.length;n<e;n++)if(t=[],r=[],!o(arguments[0],arguments[n]))return!1;return!0}var _findPuzzle=function(n){return $("img[src='"+n+"']")},_toAnagram=function(n){for(var e={},t=0;t<n.length;t++)e[n[t]]||(e[n[t]]=0),e[n[t]]+=1;return e},_buildAnagram=function(){if(!document._anagram){var n=[];n.push(...["OR","IN","AS","SUM","AND","AVG","MAX","MIN"]),n.push(...["FROM","LIKE","TRIM","WHERE","COUNT","CONCAT","SELECT","HAVING","SUBSTR","LENGTH"]),n.push(...["BETWEEN","REPLACE","ORDER BY","DISTINCT","GROUP BY","CREATE VIEW","ALTER TABLE","CREATE TABLE","CREATE INDEX"]),n.push(...["autonomous","adwc simple","oracle adwc","adwc easy"]),document._anagram=[];for(var e=0;e<n.length;e++){var t=n[e].toUpperCase(),r=[_toAnagram(t),t];document._anagram.push(r)}console.log("Anagram built"),console.log(document._anagram)}},_search=function(n){for(var e=0;e<document._anagram.length;e++)if(deepCompare(document._anagram[e][0],_toAnagram(n)))return document._anagram[e][1];return"NOT_FOUND"};_buildAnagram();var _solveKey=function(n){var e=_findPuzzle(n);if(e.length>1){for(var t=e.parent(),r=[],o=1;o<e.length;o++){var a=t[o].children[1].innerText;0==a.length&&(a=" "),r.push(a)}var i=_search(r);console.log("solving: "+r+" --\x3e "+i),$("#hiddeninput").val(i)}},_solve=function(){for(var n=["img/dest/game-triblue.png","img/dest/game-triblack.png","img/dest/game-trio.png","img/dest/game-trir.png"],e=0;e<n.length;e++)setTimeout(n=>{_solveKey(n)},100*e,n[e])},_autoSolve=function(){document._autoInterval=setInterval(_solve,1e3)},_stopSolve=function(){clearInterval(document._autoInterval)};_autoSolve(); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deepCompare() { | |
var i, l, leftChain, rightChain; | |
function compare2Objects(x, y) { | |
var p; | |
// remember that NaN === NaN returns false | |
// and isNaN(undefined) returns true | |
if (isNaN(x) && isNaN(y) && typeof x === 'number' && typeof y === 'number') { | |
return true; | |
} | |
// Compare primitives and functions. | |
// Check if both arguments link to the same object. | |
// Especially useful on the step where we compare prototypes | |
if (x === y) { | |
return true; | |
} | |
// Works in case when functions are created in constructor. | |
// Comparing dates is a common scenario. Another built-ins? | |
// We can even handle functions passed across iframes | |
if ((typeof x === 'function' && typeof y === 'function') || | |
(x instanceof Date && y instanceof Date) || | |
(x instanceof RegExp && y instanceof RegExp) || | |
(x instanceof String && y instanceof String) || | |
(x instanceof Number && y instanceof Number)) { | |
return x.toString() === y.toString(); | |
} | |
// At last checking prototypes as good as we can | |
if (!(x instanceof Object && y instanceof Object)) { | |
return false; | |
} | |
if (x.isPrototypeOf(y) || y.isPrototypeOf(x)) { | |
return false; | |
} | |
if (x.constructor !== y.constructor) { | |
return false; | |
} | |
if (x.prototype !== y.prototype) { | |
return false; | |
} | |
// Check for infinitive linking loops | |
if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1) { | |
return false; | |
} | |
// Quick checking of one object being a subset of another. | |
// todo: cache the structure of arguments[0] for performance | |
for (p in y) { | |
if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) { | |
return false; | |
} else if (typeof y[p] !== typeof x[p]) { | |
return false; | |
} | |
} | |
for (p in x) { | |
if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) { | |
return false; | |
} else if (typeof y[p] !== typeof x[p]) { | |
return false; | |
} | |
switch (typeof (x[p])) { | |
case 'object': | |
case 'function': | |
leftChain.push(x); | |
rightChain.push(y); | |
if (!compare2Objects(x[p], y[p])) { | |
return false; | |
} | |
leftChain.pop(); | |
rightChain.pop(); | |
break; | |
default: | |
if (x[p] !== y[p]) { | |
return false; | |
} | |
break; | |
} | |
} | |
return true; | |
} | |
if (arguments.length < 1) { | |
return true; //Die silently? Don't know how to handle such case, please help... | |
// throw "Need two or more arguments to compare"; | |
} | |
for (i = 1, l = arguments.length; i < l; i++) { | |
leftChain = []; //Todo: this can be cached | |
rightChain = []; | |
if (!compare2Objects(arguments[0], arguments[i])) { | |
return false; | |
} | |
} | |
return true; | |
} | |
var _findPuzzle = function (img) { | |
var selector = "img[src='" + img + "']" | |
return $(selector) | |
} | |
var _toAnagram = function (word) { | |
var anagram = {} | |
for (var i = 0; i < word.length; i++) { | |
if (!anagram[word[i]]) { | |
anagram[word[i]] = 0 | |
} | |
anagram[word[i]] += 1; | |
} | |
return anagram | |
} | |
var _buildAnagram = function () { | |
if (document._anagram) { | |
return | |
} | |
var targets = []; | |
targets.push(...["OR", "IN", "AS", "SUM", "AND", "AVG", "MAX", "MIN"]); | |
targets.push(...["FROM", "LIKE", "TRIM", "WHERE", "COUNT", "CONCAT", "SELECT", "HAVING", "SUBSTR", "LENGTH"]); | |
targets.push(...["BETWEEN", "REPLACE", "ORDER BY", "DISTINCT", "GROUP BY", "CREATE VIEW", "ALTER TABLE", "CREATE TABLE", "CREATE INDEX"]); | |
targets.push(...["autonomous", "adwc simple", "oracle adwc", "adwc easy"]); | |
// build anagram | |
document._anagram = []; | |
for (var i = 0; i < targets.length; i++) { | |
var word = targets[i].toUpperCase(); | |
var anagram = _toAnagram(word); | |
var ent = [anagram, word] | |
document._anagram.push(ent) | |
} | |
console.log("Anagram built") | |
console.log(document._anagram) | |
}; | |
var _search = function (word) { | |
for (var i = 0; i < document._anagram.length; i++) { | |
if (deepCompare(document._anagram[i][0], _toAnagram(word))) { | |
return document._anagram[i][1]; | |
} | |
} | |
return "NOT_FOUND" | |
} | |
_buildAnagram(); | |
// searching | |
var _solveKey = function (key) { | |
var puzzle = _findPuzzle(key); | |
if (puzzle.length > 1) { | |
// solve this puzzle | |
var parents = puzzle.parent() | |
var word = [] | |
for (var j = 1; j < puzzle.length; j++) { | |
var t = parents[j].children[1].innerText; | |
if (t.length == 0) { | |
t = ' ' | |
} | |
word.push(t); | |
} | |
var ans = _search(word) | |
console.log("solving: " + word + " --> " + ans) | |
$("#hiddeninput").val(ans) | |
} | |
} | |
var _solve = function () { | |
var keys = ["img/dest/game-triblue.png", "img/dest/game-triblack.png", "img/dest/game-trio.png", "img/dest/game-trir.png"]; | |
for (var i = 0; i < keys.length; i++) { | |
setTimeout((key) => { | |
_solveKey(key) | |
}, i * 100, keys[i]) | |
} | |
} | |
var _autoSolve = function () { | |
document._autoInterval = setInterval(_solve, 1000) | |
} | |
var _stopSolve = function () { | |
clearInterval(document._autoInterval) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment