Created
April 25, 2014 10:51
-
-
Save shtrih/11285392 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name Taobao link getter | |
// @namespace http://use.i.E.your.homepage/ | |
// @version 0.1 | |
// @description enter something useful | |
// @match http://*.taobao.com/* | |
// @copyright 2014+, You | |
// ==/UserScript== | |
// a function that loads jQuery and calls a callback function when jQuery has finished loading | |
function addJQuery(callback) { | |
var script = document.createElement("script"); | |
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"); | |
script.addEventListener('load', function() { | |
var script = document.createElement("script"); | |
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();"; | |
document.body.appendChild(script); | |
}, false); | |
document.body.appendChild(script); | |
} | |
// the guts of this userscript | |
function main() { | |
// Note, jQ replaces $ to avoid conflicts. | |
jQ('.main-list.hl-list').last().append( | |
jQ('<li/>', { | |
html: jQ('<a/>', { | |
click: function () { | |
var links = ''; | |
jQ('a[href^="http://item"],a[href^="http://detail"]').each(function () { | |
//links += "\n" + jQ(this).attr('href'); | |
console.log(jQ(this).attr('href')); | |
}); | |
//console.log(links); | |
}, | |
text: 'Get links!', | |
href: '#' | |
}) | |
}) | |
); | |
} | |
// load jQuery and execute the main function | |
addJQuery(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment