-
Notifications
You must be signed in to change notification settings - Fork 69
/
mip-ad-link.js
50 lines (50 loc) · 2.09 KB
/
mip-ad-link.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @file mip-ad-link 康网图片增加链接代码
* @author cnkang
*/
define(function (require) {
var $ = require('zepto');
var util = require('util');
var platform = util.platform;
var customElement = require('customElement').create();
customElement.prototype.build = function () {
$('#article_body').find('mip-img').parent().css('text-indent', 'initial');
$('#article_body').find('mip-img').parent().css('text-align', 'center');
$('#article_body').find('mip-img').parent().append('<a href="https://m.cnkang.com/pic/" class="tianjia">点击图片,查看无码私图(套图)</a>');
$(function () {
var imgs = $('#article_body mip-img');
if (imgs.length) {
$.ajax({
url: 'https://m.cnkang.com/cnkang/getarticleimglink',
dataType: 'jsonp',
data: '',
jsonp: 'callback',
success: function (data) {
var urls = data.url;
urls = shuffle(urls).slice(0, imgs.length);
imgs.each(function (index, el) {
$(this).wrap('<a href = ' + urls[index] + '/></a>');
});
}
});
}
function shuffle(array) {
var currentIndex = array.length;
while (0 !== currentIndex && 0 !== undefined) {
var randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
var temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
});
$('[data-wtf]').on('click', function (event) {
event.preventDefault();
var jumpUrl = $(this).attr('data-wtf');
location.href = jumpUrl;
});
};
return customElement;
});