Last active
April 15, 2017 05:16
-
-
Save Flower7C3/516d3560c6bfbc8694ea3f7d965628e5 to your computer and use it in GitHub Desktop.
Claim free book from PaktPub.com - just add min script as bookmark
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
var PaktPub = (function () { | |
"use strict"; | |
var freeLearningURL = 'https://www.packtpub.com/packt/offers/free-learning', | |
logoutURL = 'https://www.packtpub.com/logout'; | |
var notify = function (message, timeout) { | |
var useNotificationAPI = false; | |
if ("Notification" in window) { | |
if (Notification.permission === "granted") { | |
useNotificationAPI = true; | |
} else if (Notification.permission !== 'denied') { | |
Notification.requestPermission(function (permission) { | |
if (permission === "granted") { | |
useNotificationAPI = true; | |
console.log('Notification API granted!') | |
} else { | |
console.log('Notification API denied!') | |
} | |
}); | |
} | |
} | |
console.log('useNotificationAPI:', useNotificationAPI); | |
if (useNotificationAPI === true) { | |
var notification = new Notification(message); | |
if (typeof timeout === 'undefined') { | |
timeout = 5000; | |
} | |
setTimeout(notification.close.bind(notification), timeout); | |
} else { | |
alert(message) | |
} | |
}; | |
var checkSite = function () { | |
var currentURL = window.location.protocol + '//' + window.location.host + window.location.pathname; | |
if (currentURL === freeLearningURL) { | |
return true; | |
} | |
return false; | |
}; | |
var checkCount = 0; | |
var claimBook = function () { | |
var url = $('.free-ebook a').attr('href'); | |
if (checkCount > 2) { | |
notify("Loop warning., but it's 3rd try to check and we want forever looping :/"); | |
} else { | |
notify("Checking new book for claim."); | |
$.get(url) | |
.done(function (response) { | |
var bookName = $('.dotd-title').text().trim(); | |
notify('Yeah. Book "' + bookName + '" was claimed :)'); | |
signOut(); | |
}) | |
.fail(function () { | |
signIn(); | |
}) | |
.always(function () { | |
checkCount++ | |
}); | |
} | |
}; | |
var signInFormID = '#packt-user-login-form', | |
signInLoginID = '#email', | |
signInPassID = '#password'; | |
var signIn = function () { | |
notify('I need to authenticate You on page.'); | |
var signInLoginVal = $(signInLoginID).val() || prompt("What is Your username?"); | |
$(signInLoginID).val(signInLoginVal); | |
var signInPassVal = $(signInPassID).val() || prompt("And what is Your password?"); | |
$(signInPassID).val(signInPassVal); | |
$(signInFormID) | |
.submit(function (event) { | |
notify("Thanks. I will try to authenticate You on page..."); | |
event.preventDefault(); | |
var formUrl = $(signInFormID).attr('action'); | |
var formData = $(signInFormID).serialize(); | |
$.post(formUrl, formData) | |
.always(function () { | |
notify("Looks good. Lets check again Your new book..."); | |
claimBook(); | |
}); | |
}) | |
.submit(); | |
}; | |
var signOut = function () { | |
notify("Thanks. Now I will logout You from PaktPub."); | |
$.get(logoutURL); | |
}; | |
var redirectToSite = function () { | |
notify("You are not on PackPub's Free Technology eBooks site. Let me redirect You there..."); | |
window.location = freeLearningURL; | |
}; | |
var init = function () { | |
if (checkSite()) { | |
claimBook(); | |
} else { | |
redirectToSite(); | |
} | |
}; | |
return { | |
init: init | |
}; | |
}()); | |
PaktPub.init(); | |
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
// packed with http://dean.edwards.name/packer/ | |
javascript:eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('1 r=(3(){"15 16";1 f=\'D://E.F.G/H/17/J-18\',K=\'D://E.F.G/L\';1 g=3(b,c){1 d=M;4("5"19 6){4(5.N==="t"){d=9}7 4(5.N!==\'O\'){5.1a(3(a){4(a==="t"){d=9;u.v(\'5 P t!\')}7{u.v(\'5 P O!\')}})}}u.v(\'1b:\',d);4(d===9){1 e=w 5(b);4(1c c===\'1d\'){c=1e}1f(e.1g.1h(e),c)}7{1i(b)}};1 h=3(){1 a=6.p.1j+\'//\'+6.p.1k+6.p.1l;4(a===f){x 9}x M};1 i=0;1 j=3(){1 c=$(\'.J-1m a\').Q(\'1n\');4(i>2){g("1o 1p., 1q 1r\'s 1s R y S 1t 1u 1v 1w 1x :/")}7{g("1y w T 1z 1A.");$.U(c).1B(3(a){1 b=$(\'.1C-1D\').1E().1F();g(\'1G. 1H "\'+b+\'" 1I 1J :)\');m()}).1K(3(){l()}).V(3(){i++})}};1 k=\'#H-1L-1M-1N\',z=\'#1O\',A=\'#W\';1 l=3(){g(\'I 1P y X 8 B Y.\');1 d=$(z).q()||Z("1Q 10 C 1R?");$(z).q(d);1 e=$(A).q()||Z("1S 1T 10 C W?");$(A).q(e);$(k).11(3(a){g("12. I 13 R y X 8 B Y...");a.1U();1 b=$(k).Q(\'1V\');1 c=$(k).1W();$.1X(b,c).V(3(){g("1Y 1Z. 20 S 21 C w T...");j()})}).11()};1 m=3(){g("12. 22 I 13 L 8 23 r.");$.U(K)};1 n=3(){g("8 24 25 B 26\'s 27 28 29 2a. 2b 2c 2d 8 2e...");6.p=f};1 o=3(){4(h()){j()}7{n()}};x{14:o}}());r.14();',62,139,'|var||function|if|Notification|window|else|You|true||||||||||||||||location|val|PaktPub||granted|console|log|new|return|to|signInLoginID|signInPassID|on|Your|https|www|packtpub|com|packt||free|logoutURL|logout|false|permission|denied|API|attr|try|check|book|get|always|password|authenticate|page|prompt|is|submit|Thanks|will|init|use|strict|offers|learning|in|requestPermission|useNotificationAPI|typeof|undefined|5000|setTimeout|close|bind|alert|protocol|host|pathname|ebook|href|Loop|warning|but|it|3rd|and|we|want|forever|looping|Checking|for|claim|done|dotd|title|text|trim|Yeah|Book|was|claimed|fail|user|login|form|email|need|What|username|And|what|preventDefault|action|serialize|post|Looks|good|Lets|again|Now|from|are|not|PackPub|Free|Technology|eBooks|site|Let|me|redirect|there'.split('|'),0,{})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment