-
-
Save radinreth/988103a3e400a0ed2cc091aa650b5797 to your computer and use it in GitHub Desktop.
syncfusion-ebook-links
This file contains hidden or 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
{ | |
"manifest_version": 2, | |
"name": "Syncfusion e-book links", | |
"description": "Replace DOWNLOAD buttons by convenient links", | |
"version": "1.0", | |
"content_scripts": [ { | |
"js": [ "jquery-1.11.1.min.js", "script.js" ], | |
"matches": [ "https://www.syncfusion.com/resources/techportal/ebooks" ] | |
} ] | |
} |
This file contains hidden or 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 generateMarkDown() { | |
var origin = document.location.origin; | |
var books = $("#layout22a > div > div > div").map(function() { | |
var title = $(this).find("h3 a").text().trim(); | |
var img = origin + $(this).find("img").attr('src'); | |
var pdf = origin + $(this).find("a.download:eq(0)").attr("href"); | |
var mobi = origin + $(this).find("a.download:eq(1)").attr("href"); | |
return "# " + title + "\n\n* [Download PDF]("+pdf+")\n* [Download MOBI]("+mobi + ")\n"; | |
}); | |
books.sort(); | |
var md = "" | |
for (var i = 0; i < books.length; i++) { | |
md += books[i] + "\n"; | |
}; | |
console.log(md); | |
} | |
function replaceNextButton() { | |
var button = $("p.download-btn input")[0]; | |
if (button == undefined) { | |
console.log("All buttons replaced"); | |
generateMarkDown(); | |
return; | |
} | |
console.log("Replacing " + button.name + "..."); | |
$.post("https://www.syncfusion.com/resources/techportal/ebooks", | |
"downloadURL=%2Fresources%2Ftechportal%2Febooks%2F"+button.name, | |
function(data) { | |
var links = $("a.download", data); | |
if (links.length>0) { | |
console.log("Replacing " + button.name + "... OK"); | |
$(button).replaceWith(links); | |
} | |
else { | |
console.log("Replacing " + button.name + "... Failed"); | |
} | |
replaceNextButton(); | |
}); | |
} | |
replaceNextButton(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment