2017-03-16 21:34:13 +08:00
|
|
|
|
/**
|
2019-04-27 13:50:38 +08:00
|
|
|
|
* 原始代码来自 bangbang(http://lmbtfy.cn/),mengkun(https://mkblog.cn) 在原作的基础上作了一些小修改,以适应移动端浏览
|
|
|
|
|
|
* Github 地址:https://github.com/mengkunsoft/lmbtfy
|
|
|
|
|
|
*
|
|
|
|
|
|
* 转载或使用时,还请保留以上信息,谢谢!
|
2017-03-16 21:34:13 +08:00
|
|
|
|
*/
|
2019-04-27 13:50:38 +08:00
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
|
/* 复制结果 */
|
|
|
|
|
|
var clipboard = new ClipboardJS('.btn-copy');
|
|
|
|
|
|
clipboard.on('success', function(e) {
|
|
|
|
|
|
if (e.trigger.disabled === false || e.trigger.disabled === undefined) {
|
|
|
|
|
|
showTips('<span style="color: #4caf50">复制成功!赶紧把链接甩给伸手党们!</span>');
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
clipboard.on('error', function(e) {
|
|
|
|
|
|
showTips('<span style="color: red">复制失败,请手动复制</span>');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var $outputLink = $('#output-link');
|
|
|
|
|
|
$('#search').on('click', function () {
|
|
|
|
|
|
var link = window.location.origin + window.location.pathname + '?' + encodeURIComponent($('#kw').val());
|
|
|
|
|
|
$('#output-box').fadeIn();
|
|
|
|
|
|
showTips('复制下面的地址');
|
|
|
|
|
|
$outputLink.val(link).focus().select();
|
|
|
|
|
|
|
|
|
|
|
|
/* 尝试缩短网址 */
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
|
url: 'api.php?url=' + encodeURIComponent(link),
|
|
|
|
|
|
dataType: 'json',
|
2017-03-16 21:34:13 +08:00
|
|
|
|
success: function (data) {
|
2019-04-27 13:50:38 +08:00
|
|
|
|
if(data.code == 200) $outputLink.val(data.result).focus().select();
|
2017-03-16 21:34:13 +08:00
|
|
|
|
}
|
2019-04-27 13:50:38 +08:00
|
|
|
|
});
|
2017-03-16 21:34:13 +08:00
|
|
|
|
});
|
2019-04-27 13:50:38 +08:00
|
|
|
|
|
|
|
|
|
|
/* 预览 */
|
2017-03-16 21:34:13 +08:00
|
|
|
|
var $container = $('.container');
|
2019-04-27 13:50:38 +08:00
|
|
|
|
$container.on('click', '#btn-preview', function () {
|
|
|
|
|
|
var link = $outputLink.val();
|
|
|
|
|
|
if (!!link) {
|
|
|
|
|
|
window.open(link);
|
2017-03-16 21:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2019-04-27 13:50:38 +08:00
|
|
|
|
|
|
|
|
|
|
/* 回车搜索 */
|
2017-03-16 21:34:13 +08:00
|
|
|
|
var $kw = $('#kw');
|
|
|
|
|
|
$kw.on('keydown', function (e) {
|
2019-04-27 13:50:38 +08:00
|
|
|
|
if (e.keyCode == 13) {
|
2017-03-16 21:34:13 +08:00
|
|
|
|
$('#search').trigger('click');
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2019-04-27 13:50:38 +08:00
|
|
|
|
|
|
|
|
|
|
if (!!window.location.search) {
|
2017-03-16 21:34:13 +08:00
|
|
|
|
var kw = decodeURIComponent(window.location.search.substr(1));
|
|
|
|
|
|
var $arrow = $('#arrow');
|
2019-04-27 13:50:38 +08:00
|
|
|
|
|
|
|
|
|
|
showTips('让我来帮你百度一下');
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
showTips('1、找到输入框并选中');
|
2017-03-16 21:34:13 +08:00
|
|
|
|
$arrow.show().animate({
|
|
|
|
|
|
left: $kw.offset().left + 10 + 'px',
|
|
|
|
|
|
top: ($kw.offset().top + $kw.height()/2) + 'px'
|
2019-04-27 13:50:38 +08:00
|
|
|
|
}, 2000, function () {
|
|
|
|
|
|
showTips('2、输入你的问题');
|
2017-03-16 21:34:13 +08:00
|
|
|
|
$arrow.hide();
|
|
|
|
|
|
var $kw = $('#kw');
|
|
|
|
|
|
$kw.focus();
|
|
|
|
|
|
var i = 0;
|
2019-04-27 13:50:38 +08:00
|
|
|
|
var interval = setInterval(function () {
|
2017-03-16 21:34:13 +08:00
|
|
|
|
$kw.val(kw.substr(0,i));
|
|
|
|
|
|
i++;
|
2019-04-27 13:50:38 +08:00
|
|
|
|
if (i > kw.length) {
|
2017-03-16 21:34:13 +08:00
|
|
|
|
clearInterval(interval);
|
2019-04-27 13:50:38 +08:00
|
|
|
|
showTips('3、点击下“百度一下”按钮');
|
2017-03-16 21:34:13 +08:00
|
|
|
|
$arrow.show();
|
|
|
|
|
|
var $search = $('#search');
|
|
|
|
|
|
$arrow.animate({
|
|
|
|
|
|
left: $search.offset().left + $search.width()/2 + 'px',
|
|
|
|
|
|
top: $search.offset().top + $search.height()/2 + 'px'
|
|
|
|
|
|
}, 1000, function () {
|
2019-04-27 13:50:38 +08:00
|
|
|
|
showTips('<strong>这对你而言就是这么困难么?</strong>');
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
|
window.location = 'https://www.baidu.com/s?ch=3&ie=utf-8&wd=' + encodeURIComponent(kw);
|
2017-03-16 21:34:13 +08:00
|
|
|
|
}, 2000);
|
2019-04-27 13:50:38 +08:00
|
|
|
|
});
|
2017-03-16 21:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}, 200);
|
|
|
|
|
|
});
|
|
|
|
|
|
}, 1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2019-04-27 13:50:38 +08:00
|
|
|
|
/* 显示提示信息 */
|
|
|
|
|
|
function showTips(tips) {
|
|
|
|
|
|
$('#instructions').html(tips);
|
2017-03-16 21:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-27 13:50:38 +08:00
|
|
|
|
/* 弹出关于信息 */
|
|
|
|
|
|
function showAbout() {
|
|
|
|
|
|
var windowWidth = $(window).width(),
|
|
|
|
|
|
windowHeight = $(window).height(),
|
|
|
|
|
|
popupHeight = $("#about-box").height(),
|
|
|
|
|
|
popupWidth = $("#about-box").width();
|
|
|
|
|
|
|
|
|
|
|
|
$("#about-box").css({
|
|
|
|
|
|
"position": "absolute",
|
|
|
|
|
|
"left": windowWidth / 2 - popupWidth / 2,
|
|
|
|
|
|
"top": windowHeight / 2 - popupHeight / 2
|
|
|
|
|
|
}).fadeIn(200);
|
2017-03-16 21:34:13 +08:00
|
|
|
|
}
|