-
-
Save wilbeibi/aa8cfbc9078c66cf7d385e3358fa1bce to your computer and use it in GitHub Desktop.
显示豆瓣用户id和性别
This file contains 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 显示豆瓣用户id和性别 | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author J.Y Han | |
// @match https://www.douban.com/people/* | |
// @grant showDoubanIdAndGender | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function getCookie(name) { | |
let nameEQ = name + "=" | |
let ca = document.cookie.split(';') | |
let i | |
let c | |
for(i=0;i < ca.length;i++) { | |
c = ca[i]; | |
while (c.charAt(0)==' ') c = c.substring(1,c.length); | |
if (c.indexOf(nameEQ) === 0) { | |
return c.substring(nameEQ.length,c.length).replace(/\"/g,''); | |
} | |
} | |
return null; | |
} | |
let uid = '' | |
const ck = getCookie('ck') | |
if ($('.userface').size() > 0) { | |
uid = $('.userface').attr('src').split('ul')[1].split('-')[0] | |
$('.user-info .pl').append(`<div>ID: ${uid}</div>`) | |
} | |
if ($('.mod-usercard').size() > 0) { | |
uid = $('.mod-usercard .pic img').attr('src').split('icon/u')[1].split('-')[0] | |
$('.mod-usercard .usercard-loc').after(`<div>ID: ${uid}</div>`) | |
} | |
if (ck) { | |
const loader = `<div id="gender-pending">正在获取...</div>` | |
if ($('.userface').size() > 0) { | |
$('.user-info .pl').append(loader) | |
} | |
if ($('.mod-usercard').size() > 0) { | |
$('.mod-usercard .usercard-loc').after(loader) | |
} | |
$.ajax({ | |
url: `https://m.douban.com/rexxar/api/v2/user/${uid}?ck=${ck}&for_mobile=1`, | |
method: 'GET', | |
success: (resp) => { | |
if (resp) { | |
let gender = resp.gender === 'F' ? '女' : resp.gender === 'M' ? '男' : '未设置' | |
$('#gender-pending').html(`<div>性别:${gender}</div>`) | |
} | |
}, | |
error: () => { | |
$('#gender-pending').html('获取失败') | |
} | |
}) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment