Last active
March 6, 2016 12:15
-
-
Save think2011/53fe08923ced04f10ca0 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
/* | |
var script = document.createElement('script'); | |
var p1 = encodeURIComponent("$('#data_list tr').find('td:eq(2) a')"); | |
var p2 = encodeURIComponent('.intro img'); | |
script.src = `https://rawgit.com/think2011/53fe08923ced04f10ca0/raw/4bad14cd67c835306d93a01b5ea377fe354081d1/previewPic.js?${p1}&${p2}`; | |
document.body.appendChild(script); | |
*/ | |
jsReady(() => { | |
var params = deUrlParams(); | |
previewPic(params[0], params[1]); | |
}); | |
/** | |
* 抓取链接中的第一张图并放到链接区域内 | |
* | |
* @param allA {eval} 链接选择器源码串 | |
* @param firstImg 首图的选择器 | |
*/ | |
function previewPic(allA, firstImg) { | |
eval(allA).each((k, v) => { | |
var $a = $(v); | |
$.get($a.attr('href'), function(data) { | |
var img = $(data).find(firstImg)[0]; | |
img.style.width = '100%'; | |
$a.append(img); | |
}); | |
}); | |
} | |
/** | |
* 从url中解析出参数 | |
* @return {[type]} [description] | |
*/ | |
function deUrlParams () { | |
var params = (document.scripts[document.scripts.length-2].src).split('?'); | |
params = params[1].split('&'); | |
return [decodeURIComponent(params[0]), decodeURIComponent(params[1])]; | |
} | |
/** | |
* 初始化脚本 | |
*/ | |
function jsReady(fn) { | |
var script = document.createElement('script'); | |
script.src = 'http://cdn.bootcss.com/jquery/2.1.4/jquery.min.js'; | |
document.body.appendChild(script); | |
script.onload = fn; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment