Export csv from qimai.cn
目前為
// ==UserScript==
// @name QiMai.cn Exporter
// @description Export csv from qimai.cn
// @author kawais
// @namespace kawais
// @include /www\.qimai\.cn/rank/.*$/
// @version 1.0
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.0/jquery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.16.9/xlsx.min.js
// @grant GM.xmlhttpRequest
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
console.log(GM_info);
(function () {
var css = [
'#exporter {',
' position: fixed;',
' padding: 7px;',
' background-color: #F8EEB1;',
' border: 2px solid #333;',
' border-radius: 6px;',
' z-index: 9999;',
' font-size: 18px;',
' right: 30px;',
' bottom: 20px;',
' color: #000;',
' width: 650px;',
' text-align: center;',
' box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5), 0 0 15px rgba(0, 0, 0, 0.3);',
'}'
].join('\n');
if (typeof GM_addStyle != 'undefined') {
GM_addStyle(css);
} else if (typeof PRO_addStyle != 'undefined') {
PRO_addStyle(css);
} else if (typeof addStyle != 'undefined') {
addStyle(css);
} else {
var node = document.createElement('style');
node.type = 'text/css';
node.appendChild(document.createTextNode(css));
var heads = document.getElementsByTagName('head');
if (heads.length > 0) {
heads[0].appendChild(node);
} else {
// no head yet, stick it whereever
document.documentElement.appendChild(node);
}
}
}) ();
var html = '<div id="exporter">' +
'Export'+
'</div>';
$('body').prepend(html);
$('#exporter').click(function(){
doExport();
})
function pad(num, size) {
var s = "000000000" + num;
return s.substr(s.length-size);
}
function encode(t,n){
t = t.split('')
let Et=0,tf=10
for (var a = t.length, e = n.length, s = 'charCodeAt', i = Et; i < a; i++)
t[i] = String.fromCharCode(t[i][s](Et) ^ n[(i + tf) % e][s](Et));
return encodeURIComponent(btoa(t.join('')))
}
function doExport() {
let arr=location.href.split('/')
for(var i=5,params={};i<arr.length;i++){
params[arr[i]]=arr[i+1]
i++
}
console.log(params)
let vals=Object.values(params).sort().join('')
let t=new Date - (0) - 1515125653845
let str=`${btoa(vals)}@#/rank/${arr[4]}@#${t}@#1`
let key='00000008d78d46a'
params.analysis=encode(str,key)
let url=location.href.split('/').slice(0,5).join('/').replace('//www.','//api.')
$.ajax({
dataType: 'json',
async: false,
url: url,
data:params
}).done(function (data) {
console.log(data)
});
return
/*
saveAsType=$('input[name="saveAs"]:checked').val();
$('#savePNG button').prop('disabled', true);
var href = window.location.href;
var domain = href.split('/') [2];
id = href.match(/id=([^&]+)/) [1];
title = $('title').text().split(' - ')[0].replace(/\s+/g,'_');
var pid = 'PP1';
var count = parseInt($('#count').val());
var max = parseInt($('#max').val());
var url = 'https://' + domain + '/books?id=' + id + '&lpg=' + pid + '&pg=' + pid + '&jscmd=click3';
$.ajax({
dataType: 'json',
async: false,
url: url,
}).done(function (data) {
pids = $.map(data.page, function (val, i) {
if (i > 3) {
return val.pid;
}
});
});
var number = pids.length;
$('#total').val(number);
if(max===0) {
max=number;
$('#max').val(max);
}
if (count >= number) {
alert('Wrong number of pages. There are only ' + number + ' available.');
$('#savePNG button').prop('disabled', false);
} else {
var i = count;
var timer = setInterval(function () {
if (i == max || i == number) {
clearInterval(timer);
alert('Downloaded every available page out of '+ number + ' total. Saving…');
save(i, number);
return false;
}
var url = 'https://' + domain + '/books?id=' + id + '&lpg=' + pids[i] + '&pg=' + pids[i] + '&jscmd=click3';
$.ajax({
dataType: 'json',
async: false,
url: url,
}).done(function (data) {
if (data.page[0].hasOwnProperty('src') || data.page[0].flags == 8) {
var url = data.page[0].src + '&w=1600';
var name = pad((i+1), number.toString().length) + '_' + pids[i];
if (data.page[0].flags == 8) {
$('#count').val(i + 1);
$('#count').css('font-weight', 'bold').css('text-decoration', 'line-through');
} else {
try{
addIMG(url, name, (i + 1));
}catch(e){
console.log(e);
}
}
i=i+1;
} else {
clearInterval(timer);
alert('Can\'t download more.\n' +
'Saving ' + i + ' out of ' + number + ' pages…\n' +
'Change your IP and continue!');
save(i, number);
}
});
}, 400);
}
*/
}