-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAltmetric-Badge-CN.user.js
More file actions
114 lines (109 loc) · 5.36 KB
/
Altmetric-Badge-CN.user.js
File metadata and controls
114 lines (109 loc) · 5.36 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// ==UserScript==
// @name Altmetric Badge (CN)
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Automatically shows the Altmetric badge on academic publisher websites (China-Optimized). Uses Base64 icon for fast loading without VPN.
// @author skymagician
// @match https://webvpn.zju.edu.cn/*
// @match https://doi.org/*
// @match https://*.sciencedirect.com/*
// @match https://*.nature.com/*
// @match https://*.wiley.com/*
// @match https://*.springer.com/*
// @match https://*.tandfonline.com/*
// @match https://academic.oup.com/*
// @match https://*.aeaweb.org/*
// @match https://*.sagepub.com/*
// @match https://*.cambridge.org/*
// @match https://ieeexplore.ieee.org/*
// @match https://*.acm.org/*
// @match https://*.pnas.org/*
// @match https://*.sciencemag.org/*
// @match https://*.science.org/*
// @match https://*.jamanetwork.com/*
// @match https://*.bmj.com/*
// @match https://*.uchicago.edu/*
// @match https://arxiv.org/*
// @grant GM_addStyle
// @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48cGF0aCBkPSJNNTAgNTAgTDUwIDAgQTUwIDUwIDAgMCAxIDEwMCA1MCBaIiBmaWxsPSIjRkYzQjMwIi8+PHBhdGggZD0iTTUwIDUwIEwxMDAgNTAgQTUwIDUwIDAgMCAxIDUwIDEwMCBaIiBmaWxsPSIjRjFDNDBGIi8+PHBhdGggZD0iTTUwIDUwIEw1MCAxMDAgQTUwIDUwIDAgMCAxIDAgNTAgWiIgZmlsbD0iIzAwN0FGRiIvPjxwYXRoIGQ9Ik01MCA1MCBMMCA1MCBBNTAgNTAgMCAwIDEgNTAgMCBaIiBmaWxsPSIjMDBBOUNDIi8+PGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iMjUiIGZpbGw9IiNGRkZGRkYiLz48L3N2Zz4=
// @license MIT
// @downloadURL https://raw.githubusercontent.com/skymagician/Altmetric-Badge-UserScript/main/Altmetric-Badge-CN.user.js
// @updateURL https://raw.githubusercontent.com/skymagician/Altmetric-Badge-UserScript/main/Altmetric-Badge-CN.user.js
// ==/UserScript==
(function () {
"use strict";
// === Config ===
// SVG Base64 Icon (Network Independent)
const LOGO_BASE64 =
"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48cGF0aCBkPSJNNTAgNTAgTDUwIDAgQTUwIDUwIDAgMCAxIDEwMCA1MCBaIiBmaWxsPSIjRkYzQjMwIi8+PHBhdGggZD0iTTUwIDUwIEwxMDAgNTAgQTUwIDUwIDAgMCAxIDUwIDEwMCBaIiBmaWxsPSIjRjFDNDBGIi8+PHBhdGggZD0iTTUwIDUwIEw1MCAxMDAgQTUwIDUwIDAgMCAxIDAgNTAgWiIgZmlsbD0iIzAwN0FGRiIvPjxwYXRoIGQ9Ik01MCA1MCBMMCA1MCBBNTAgNTAgMCAwIDEgNTAgMCBaIiBmaWxsPSIjMDBBOUNDIi8+PGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iMjUiIGZpbGw9IiNGRkZGRkYiLz48L3N2Zz4=";
const BOTTOM_DISTANCE = "30px";
const AUTO_OPEN = false;
const css = `
#altmetric-master-btn { position: fixed; bottom: ${BOTTOM_DISTANCE}; right: 0; z-index: 2147483647; background: #fff; border: 1px solid #ddd; border-right: none; padding: 8px; border-radius: 8px 0 0 8px; cursor: pointer; box-shadow: -2px -2px 10px rgba(0,0,0,0.1); width: 48px; height: 48px; transition: all 0.2s ease; display: flex; align-items: center; justify-content: center; user-select: none; }
#altmetric-master-btn:hover { width: 58px; background: #fcfcfc; box-shadow: -2px -4px 12px rgba(0,0,0,0.15); }
#altmetric-master-btn img { width: 32px; height: 32px; object-fit: contain; transition: transform 0.3s ease; }
#altmetric-master-btn:active img { transform: scale(0.9); }
@keyframes spin { 100% { transform: rotate(360deg); } }
#altmetric-master-btn.is-loading img { animation: spin 0.8s linear infinite; opacity: 0.8; }
`;
const styleEl = document.createElement("style");
styleEl.innerHTML = css;
document.head.appendChild(styleEl);
var btn = document.createElement("div");
btn.id = "altmetric-master-btn";
btn.title = "Toggle Altmetric Badge";
btn.innerHTML = `<img src="${LOGO_BASE64}" alt="Altmetric">`;
document.body.appendChild(btn);
var isToggling = false;
btn.onclick = function (e) {
e.stopPropagation();
e.preventDefault();
if (isToggling) return;
isToggling = true;
var popover = document.getElementById("_altmetric_popover_el");
if (!popover) {
loadScript();
} else {
popover.remove();
document
.querySelectorAll('script[src*="d1bxh8uas1mnw7.cloudfront.net"]')
.forEach((s) => s.remove());
setTimeout(() => {
isToggling = false;
}, 300);
}
};
function loadScript() {
btn.classList.add("is-loading");
document
.querySelectorAll('script[src*="d1bxh8uas1mnw7.cloudfront.net"]')
.forEach((s) => s.remove());
var oldPopover = document.getElementById("_altmetric_popover_el");
if (oldPopover) oldPopover.remove();
var script = document.createElement("script");
script.setAttribute(
"src",
"https://d1bxh8uas1mnw7.cloudfront.net/assets/content.js?" + Date.now(),
);
script.setAttribute("type", "text/javascript");
script.setAttribute("async", "true");
document.body.appendChild(script);
var checkTimer = setInterval(() => {
var p = document.getElementById("_altmetric_popover_el");
if (p) {
clearInterval(checkTimer);
btn.classList.remove("is-loading");
isToggling = false;
}
}, 500);
setTimeout(() => {
clearInterval(checkTimer);
btn.classList.remove("is-loading");
isToggling = false;
}, 5000);
}
if (AUTO_OPEN) {
isToggling = true;
setTimeout(loadScript, 1500);
}
})();