Last active
December 25, 2023 20:50
-
-
Save naoyeye/1179f0b7114250bf3a88a756e75cd915 to your computer and use it in GitHub Desktop.
显示豆瓣用户id和性别
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
// ==UserScript== | |
// @name Douban-Profile-Plus | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description 显示豆瓣用户id|性别 | |
// @author J.Y Han | |
// @match https://www.douban.com/people/* | |
// ==/UserScript== | |
/* globals $ */ | |
(function() { | |
'use strict'; | |
// 创建一个居中的窗口 | |
const openPopupCenter = (url, title, w, h) => { | |
const getSpecs = (w, h, top, left) => { | |
return `toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${w}, height=${h}, top=${top}, left=${left}`; | |
}; | |
const getFirstNumber = (potentialNumbers) => { | |
for(let i = 0; i < potentialNumbers.length; i++) { | |
const value = potentialNumbers[i]; | |
if (typeof value === 'number') { | |
return value; | |
} | |
} | |
}; | |
// Fixes dual-screen position | |
// Most browsers use window.screenLeft | |
// Firefox uses screen.left | |
const dualScreenLeft = getFirstNumber([window.screenLeft, screen.left]); | |
const dualScreenTop = getFirstNumber([window.screenTop, screen.top]); | |
const width = getFirstNumber([window.innerWidth, document.documentElement.clientWidth, screen.width]); | |
const height = getFirstNumber([window.innerHeight, document.documentElement.clientHeight, screen.height]); | |
const left = ((width / 2) - (w / 2)) + dualScreenLeft; | |
const top = ((height / 2) - (h / 2)) + dualScreenTop; | |
const newWindow = window.open(url, title, getSpecs(w, h, top, left)); | |
// Puts focus on the newWindow | |
if (window.focus) { | |
newWindow.focus(); | |
} | |
return newWindow; | |
} | |
const 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) { | |
const faceSrc = $('.userface').attr('src') | |
// 判断是不是默认头像 | |
if (faceSrc.includes('/user_normal.jpg')) { | |
// 取发豆邮按钮 | |
uid = $('.user-group').next('.a-btn').attr('href').split('=')[1] | |
} else { | |
uid = faceSrc.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>`) | |
} | |
var qrurl = `https://standbyme-2023.cup.douban/?user_id=${uid}&autorotate=false&fullscreen=true&hidenav=true&monitor_screenshot=true&pre=159&is_douban_app=true&skip_welcome=true` | |
$('.user-opt').after('<div>' + | |
'<span style="color: green; cursor: pointer;" id="standbyme_btn">2023个人书影音报告</span>' + | |
'</div>' | |
) | |
$('#standbyme_btn').click(() => { | |
openPopupCenter(qrurl, '', '390', '800'); | |
}) | |
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