GreasyFork User Dashboard

It redesigns user pages to improve the browsability.

目前為 2020-01-11 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name GreasyFork User Dashboard
  3. // @name:ja GreasyFork User Dashboard
  4. // @name:ja GreasyFork User Dashboard
  5. // @description It redesigns user pages to improve the browsability.
  6. // @description:ja 一覧性に優れた新しいユーザーページを提供します。
  7. // @description:zh-CN 提供一个一览性出色的新用户页面。
  8. // @namespace knoa.jp
  9. // @include https://gf.qytechs.cn/*/users/*
  10. // @include https://sleazyfork.org/*/users/*
  11. // @version 1.4.1
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function(){
  16. const SCRIPTNAME = 'GreasyForkUserDashboard';
  17. const DEBUG = false;/*
  18. [update] 1.4.1
  19. small fix.
  20.  
  21. [bug]
  22.  
  23. [to do]
  24. 1年以上経ったスクリプトに「いまも動作しますよ」的なアップデートを促したいけど・・・別スクリプトかな
  25.  
  26. [possible]
  27. 3カラムのレイアウト崩れる(スクリプト未使用でも発生する)
  28. グラフ数字の日付追加時くるりんぱは位置がズレるので労力に見合わないか
  29.  
  30. [not to do]
  31. */
  32. if(window === top && console.time) console.time(SCRIPTNAME);
  33. const INTERVAL = 1000;/* for fetch */
  34. const DRAWINGDELAY = 125;/* for drawing each charts */
  35. const UPDATELINKTEXT = '+';/* for update link text */
  36. const DEFAULTMAX = 10;/* for chart scale */
  37. const DAYS = 180;/* for chart length */
  38. const STATSUPDATE = 1000*60*60;/* stats update interval of gf.qytechs.cn */
  39. const TRANSLATIONEXPIRE = 1000*60*60*24*30;/* cache time for translations */
  40. const STATSEXPIRE = 1000*60*60*24*10;/* cache time for stats */
  41. const EASING = 'cubic-bezier(0,.75,.5,1)';/* quick easing */
  42. let site = {
  43. targets: {
  44. userSection: () => $('body > header + div > section:nth-of-type(1)'),
  45. userName: () => $('body > header + div > section:nth-of-type(1) > h2'),
  46. userProfile: () => $('#user-profile'),
  47. controlPanel: () => $('#control-panel'),
  48. newScriptSetLink: () => $('a[href$="/sets/new"]'),
  49. discussionList: () => $('ul.discussion-list'),
  50. scriptSets: () => $('body > header + div > section:nth-of-type(2)'),/* section for Script Sets */
  51. scripts: () => $('body > header + div > div.sidebarred'),/* section for Scripts */
  52. userScriptSets: () => $('#user-script-sets'),
  53. userScriptList: () => $('#user-script-list'),
  54. },
  55. get: {
  56. language: (d) => d.documentElement.lang,
  57. firstScript: (list) => list.querySelector('li h2 > a'),
  58. translation: (d, t) => {
  59. let es = {
  60. info: d.querySelector('#script-links > li.current'),
  61. code: d.querySelector('#script-links > li > a[href$="/code"]'),
  62. history: d.querySelector('#script-links > li > a[href$="/versions"]'),
  63. feedback: d.querySelector('#script-links > li > a[href$="/feedback"]'),
  64. stats: d.querySelector('#script-links > li > a[href$="/stats"]'),
  65. derivatives: d.querySelector('#script-links > li > a[href$="/derivatives"]'),
  66. update: d.querySelector('#script-links > li > a[href$="/versions/new"]'),
  67. delete: d.querySelector('#script-links > li > a[href$="/delete"]'),
  68. admin: d.querySelector('#script-links > li > a[href$="/admin"]'),
  69. version: d.querySelector('#script-stats > dt.script-show-version'),
  70. }
  71. Object.keys(es).forEach((key) => t[key] = es[key] ? es[key].textContent : t[key]);
  72. t.feedback = t.feedback.replace(/\s\(\d+\)/, '');
  73. return t;
  74. },
  75. translationOnStats: (d, t) => {
  76. t.installs = d.querySelector('table.stats-table > thead > tr > th:nth-child(2)').textContent || t.installs;
  77. t.updateChecks = d.querySelector('table.stats-table > thead > tr > th:nth-child(3)').textContent || t.updateChecks;
  78. return t;
  79. },
  80. props: (li) => {return {
  81. name: li.querySelector('h2 > a'),
  82. description: li.querySelector('.description'),
  83. stats: li.querySelector('dl.inline-script-stats'),
  84. dailyInstalls: li.querySelector('dd.script-list-daily-installs'),
  85. totalInstalls: li.querySelector('dd.script-list-total-installs'),
  86. ratings: li.querySelector('dd.script-list-ratings'),
  87. createdDate: li.querySelector('dd.script-list-created-date'),
  88. updatedDate: li.querySelector('dd.script-list-updated-date'),
  89. scriptVersion: li.dataset.scriptVersion,
  90. }},
  91. scriptUrl: (li) => li.querySelector('h2 > a').href,
  92. },
  93. };
  94. const DEFAULTTRANSLATION = {
  95. info: 'Info',
  96. code: 'Code',
  97. history: 'History',
  98. feedback: 'Feedback',
  99. stats: 'Stats',
  100. derivatives: 'Derivatives',
  101. update: 'Update',
  102. delete: 'Delete',
  103. admin: 'Admin',
  104. version: 'Version',
  105. installs: 'Installs',
  106. updateChecks: 'Update checks',
  107. scriptSets: 'Script Sets',
  108. scripts: 'Scripts',
  109. };
  110. let translation = {};
  111. let elements = {}, storages = {}, timers = {};
  112. let core = {
  113. initialize: function(){
  114. core.getElements();
  115. core.read();
  116. core.clearOldData();
  117. core.addStyle();
  118. core.prepareTranslations();
  119. core.hideUserSection();
  120. core.hideProfile();
  121. core.hideControlPanel();
  122. core.addTabNavigation();
  123. core.addNewScriptSetLink();
  124. core.rebuildScriptList();
  125. core.addChartSwitcher();
  126. },
  127. getElements: function(){
  128. for(let i = 0, keys = Object.keys(site.targets); keys[i]; i++){
  129. let element = site.targets[keys[i]]();
  130. if(!element) log(`Not found: ${keys[i]}`);
  131. else{
  132. element.dataset.selector = keys[i];
  133. elements[keys[i]] = element;
  134. }
  135. }
  136. },
  137. read: function(){
  138. storages.translations = Storage.read('translations') || {};
  139. storages.shown = Storage.read('shown') || {};
  140. storages.stats = Storage.read('stats') || {};
  141. storages.chartKey = Storage.read('chartKey') || 'updateChecks';
  142. },
  143. clearOldData: function(){
  144. let now = Date.now();
  145. Object.keys(storages.stats).forEach((key) => {
  146. if(storages.stats[key].updated < now - STATSEXPIRE) delete storages.stats[key];
  147. });
  148. Storage.save('stats', storages.stats);
  149. },
  150. prepareTranslations: function(){
  151. let language = site.get.language(document);
  152. translation = storages.translations[language] || DEFAULTTRANSLATION;
  153. if(!Object.keys(DEFAULTTRANSLATION).every((key) => translation[key])){/* some change in translation keys */
  154. Object.keys(DEFAULTTRANSLATION).forEach((key) => translation[key] = translation[key] || DEFAULTTRANSLATION[key]);
  155. core.getTranslations();
  156. }else{
  157. if(site.get.language(document) === 'en') return;
  158. if(Date.now() < (Storage.saved('translations') || 0) + TRANSLATIONEXPIRE) return;
  159. core.getTranslations();
  160. }
  161. },
  162. getTranslations: function(){
  163. let firstScript = site.get.firstScript(elements.userScriptList);
  164. fetch(firstScript.href, {credentials: 'include'})
  165. .then(response => response.text())
  166. .then(text => new DOMParser().parseFromString(text, 'text/html'))
  167. .then(d => translation = storages.translations[site.get.language(d)] = site.get.translation(d, translation))
  168. .then(() => wait(INTERVAL))
  169. .then(() => fetch(firstScript.href + '/stats'))
  170. .then(response => response.text())
  171. .then(text => new DOMParser().parseFromString(text, 'text/html'))
  172. .then(d => {
  173. translation = storages.translations[site.get.language(d)] = site.get.translationOnStats(d, translation);
  174. Storage.save('translations', storages.translations);
  175. });
  176. },
  177. hideUserSection: function(){
  178. if(!elements.userProfile && !elements.discussionList && !elements.controlPanel) return;/* thin enough */
  179. let userSection = elements.userSection, more = createElement(core.html.more());
  180. if(!storages.shown.userSection) userSection.classList.add('hidden');
  181. more.addEventListener('click', function(e){
  182. userSection.classList.toggle('hidden');
  183. storages.shown.userSection = !userSection.classList.contains('hidden');
  184. Storage.save('shown', storages.shown);
  185. });
  186. userSection.appendChild(more);
  187. },
  188. hideProfile: function(){
  189. /* use userName.hidden instead of userProfile.hidden for CSS */
  190. let controlPanel = elements.controlPanel, userName = elements.userName, userProfile = elements.userProfile;
  191. if(!controlPanel) return;/* may not be own user page */
  192. if(!userProfile) return;/* no profile text */
  193. let more = createElement(core.html.more());
  194. if(!storages.shown.userProfile) userName.classList.add('hidden');
  195. more.addEventListener('click', function(e){
  196. userName.classList.toggle('hidden');
  197. storages.shown.userProfile = !userName.classList.contains('hidden');
  198. Storage.save('shown', storages.shown);
  199. });
  200. userName.appendChild(more);
  201. },
  202. hideControlPanel: function(){
  203. let controlPanel = elements.controlPanel;
  204. if(!controlPanel) return;/* may be not own user page */
  205. document.documentElement.dataset.owner = 'true';/* user owner flag */
  206. let header = controlPanel.firstElementChild;
  207. if(!storages.shown.controlPanel) controlPanel.classList.add('hidden');
  208. setTimeout(function(){elements.userSection.style.minHeight = controlPanel.offsetHeight + controlPanel.offsetTop + 'px'}, 250);/* needs delay */
  209. header.addEventListener('click', function(e){
  210. controlPanel.classList.toggle('hidden');
  211. storages.shown.controlPanel = !controlPanel.classList.contains('hidden');
  212. Storage.save('shown', storages.shown);
  213. elements.userSection.style.minHeight = controlPanel.offsetHeight + controlPanel.offsetTop + 'px';
  214. });
  215. },
  216. addTabNavigation: function(){
  217. let scriptSets = elements.scriptSets, scripts = elements.scripts;
  218. let userScriptSets = elements.userScriptSets, userScriptList = elements.userScriptList;
  219. const keys = [{
  220. label: scriptSets ? scriptSets.querySelector('header').textContent : translation.scriptSets,
  221. selector: 'scriptSets',
  222. count: userScriptSets ? userScriptSets.children.length : 0,
  223. }, {
  224. label: scripts ? scripts.querySelector('header').textContent : translation.scripts,
  225. selector: 'scripts',
  226. count: userScriptList ? userScriptList.children.length : 0,
  227. selected: true
  228. }];
  229. let nav = createElement(core.html.tabNavigation()), anchor = (scriptSets || scripts);
  230. let template = nav.querySelector('li.template');
  231. if(anchor) anchor.parentNode.insertBefore(nav, anchor);
  232. for(let i = 0; keys[i]; i++){
  233. let li = template.cloneNode(true);
  234. li.classList.remove('template');
  235. li.textContent = keys[i].label + ` (${keys[i].count})`;
  236. li.dataset.target = keys[i].selector;
  237. li.dataset.count = keys[i].count;
  238. li.addEventListener('click', function(e){
  239. /* close tab */
  240. li.parentNode.querySelector('[data-selected="true"]').dataset.selected = 'false';
  241. let openedTarget = $('[data-tabified][data-selected="true"]');
  242. if(openedTarget) openedTarget.dataset.selected = 'false';
  243. /* open tab */
  244. li.dataset.selected = 'true';
  245. let openingTarget = $(`[data-selector="${li.dataset.target}"]`);
  246. if(openingTarget) openingTarget.dataset.selected = 'true';
  247. });
  248. let target = elements[keys[i].selector];
  249. if(target){
  250. target.dataset.tabified = 'true';
  251. if(keys[i].selected) li.dataset.selected = target.dataset.selected = 'true';
  252. else li.dataset.selected = target.dataset.selected = 'false';
  253. }else{
  254. if(keys[i].selected) li.dataset.selected = 'true';
  255. else li.dataset.selected = 'false';
  256. }
  257. template.parentNode.insertBefore(li, template);
  258. }
  259. },
  260. addNewScriptSetLink: function(){
  261. let newScriptSetLink = elements.newScriptSetLink;
  262. if(!newScriptSetLink) return;/* may be not own user page */
  263. let link = newScriptSetLink.cloneNode(true), list = elements.userScriptSets, li = document.createElement('li');
  264. li.appendChild(link);
  265. list.appendChild(li);
  266. },
  267. rebuildScriptList: function(){
  268. if(!elements.userScriptList) return;
  269. for(let i = 0, list = elements.userScriptList, li; li = list.children[i]; i++){
  270. if(li.dataset.scriptId === undefined) continue;
  271. let more = createElement(core.html.more()), props = site.get.props(li), key = li.dataset.scriptName, isLibrary = li.dataset.scriptType === 'library';
  272. if(!storages.shown[key]) li.classList.add('hidden');
  273. more.addEventListener('click', function(e){
  274. li.classList.toggle('hidden');
  275. if(li.classList.contains('hidden')) delete storages.shown[key];/* prevent from getting fat storage */
  276. else storages.shown[key] = true;
  277. Storage.save('shown', storages.shown);
  278. });
  279. li.dataset.scriptUrl = props.name.href;
  280. li.appendChild(more);
  281. if(isLibrary) continue;/* not so critical to skip below by continue */
  282. /* attatch titles */
  283. props.dailyInstalls.previousElementSibling.title = props.dailyInstalls.previousElementSibling.textContent;
  284. props.totalInstalls.previousElementSibling.title = props.totalInstalls.previousElementSibling.textContent;
  285. props.ratings.previousElementSibling.title = props.ratings.previousElementSibling.textContent;
  286. props.createdDate.previousElementSibling.title = props.createdDate.previousElementSibling.textContent;
  287. props.updatedDate.previousElementSibling.title = props.updatedDate.previousElementSibling.textContent;
  288. /* wrap the description to make it an inline element */
  289. let span = document.createElement('span');
  290. span.textContent = props.description.textContent.trim();
  291. props.description.replaceChild(span, props.description.firstChild);
  292. /* Link to Code */
  293. let versionLabel = createElement(core.html.dt('script-list-version', translation.version));
  294. let versionDd = createElement(core.html.ddLink('script-list-version', props.scriptVersion, props.name.href + '/code', translation.code));
  295. versionLabel.title = versionLabel.textContent;
  296. props.stats.insertBefore(versionLabel, props.createdDate.previousElementSibling);
  297. props.stats.insertBefore(versionDd, props.createdDate.previousElementSibling);
  298. /* Link to Version up */
  299. if(elements.controlPanel){
  300. let updateLink = document.createElement('a');
  301. updateLink.href = props.name.href + '/versions/new';
  302. updateLink.textContent = UPDATELINKTEXT;
  303. updateLink.title = translation.update;
  304. updateLink.classList.add('update');
  305. versionDd.appendChild(updateLink);
  306. }
  307. /* Link to Stats from Total installs */
  308. let statsDd = createElement(core.html.ddLink('script-list-total-installs', props.totalInstalls.textContent, props.name.href + '/stats', translation.stats));
  309. props.stats.replaceChild(statsDd, props.totalInstalls);
  310. /* Link to History from Updated date */
  311. let historyDd = createElement(core.html.ddLink('script-list-updated-date', props.updatedDate.textContent, props.name.href + '/versions', translation.history));
  312. props.stats.replaceChild(historyDd, props.updatedDate);
  313. }
  314. },
  315. addChartSwitcher: function(){
  316. let userScriptList = elements.userScriptList;
  317. if(!userScriptList) return;
  318. const keys = [
  319. {label: translation.installs, selector: 'installs'},
  320. {label: translation.updateChecks, selector: 'updateChecks'},
  321. ];
  322. let nav = createElement(core.html.chartSwitcher());
  323. let template = nav.querySelector('li.template');
  324. userScriptList.parentNode.appendChild(nav);/* less affected on dom */
  325. for(let i = 0; keys[i]; i++){
  326. let li = template.cloneNode(true);
  327. li.classList.remove('template');
  328. li.textContent = keys[i].label;
  329. li.dataset.key = keys[i].selector;
  330. li.addEventListener('click', function(e){
  331. li.parentNode.querySelector('[data-selected="true"]').dataset.selected = 'false';
  332. li.dataset.selected = 'true';
  333. storages.chartKey = li.dataset.key;
  334. Storage.save('chartKey', storages.chartKey);
  335. core.drawCharts();
  336. });
  337. if(keys[i].selector === storages.chartKey) li.dataset.selected = 'true';
  338. else li.dataset.selected = 'false';
  339. template.parentNode.insertBefore(li, template);
  340. }
  341. core.drawCharts();
  342. },
  343. drawCharts: function(){
  344. let promises = [];
  345. if(timers.charts && timers.charts.length) timers.charts.forEach((id) => clearTimeout(id));/* stop all the former timers */
  346. timers.charts = [];
  347. for(let i = 0, list = elements.userScriptList, li; li = list.children[i]; i++){
  348. if(li.dataset.scriptId === undefined) continue;
  349. if(li.dataset.scriptType === 'library') continue;
  350. /* Draw chart of daily update checks */
  351. let chart = li.querySelector('.chart') || createElement(core.html.chart()), key = li.dataset.scriptName;
  352. if(storages.stats[key] && storages.stats[key].data){
  353. timers.charts[i] = setTimeout(function(){
  354. core.drawChart(chart, storages.stats[key].data.slice(-DAYS));
  355. if(!chart.isConnected) li.appendChild(chart);
  356. }, i * DRAWINGDELAY);/* CPU friendly */
  357. }
  358. let now = Date.now(), updated = (storages.stats[key]) ? storages.stats[key].updated || 0 : 0, past = updated % STATSUPDATE, expire = updated - past + STATSUPDATE;
  359. if(now < expire) continue;/* still up-to-date */
  360. promises.push(new Promise(function(resolve, reject){
  361. timers.charts[i] = setTimeout(function(){
  362. fetch(li.dataset.scriptUrl + '/stats.csv', {credentials: 'include'}/* for sensitive scripts */)/* less file size than json */
  363. .then(response => response.text())
  364. .then(csv => {
  365. let lines = csv.split('\n');
  366. lines = lines.slice(1, -1);/* cut the labels + blank line */
  367. storages.stats[key] = {data: [], updated: now};
  368. for(let i = 0; lines[i]; i++){
  369. let p = lines[i].split(',');
  370. storages.stats[key].data[i] = {
  371. date: p[0],
  372. installs: parseInt(p[1]),
  373. updateChecks: parseInt(p[2]),
  374. };
  375. }
  376. core.drawChart(chart, storages.stats[key].data.slice(-DAYS));
  377. if(!chart.isConnected) li.appendChild(chart);
  378. resolve();
  379. });
  380. }, i * INTERVAL);/* server friendly */
  381. }));
  382. }
  383. if(promises.length) Promise.all(promises).then((values) => Storage.save('stats', storages.stats));
  384. },
  385. drawChart: function(chart, stats){
  386. let dl = chart.querySelector('dl'), dt = dl.querySelector('dt.template'), dd = dl.querySelector('dd.template'), hasBars = (2 < dl.children.length);
  387. let chartKey = storages.chartKey, max = Math.max(DEFAULTMAX, ...stats.map(s => s[chartKey]));
  388. for(let i = last = stats.length - 1; stats[i]; i--){/* from last */
  389. let date = stats[i].date, count = stats[i][chartKey];
  390. let dateDt = dl.querySelector(`dt[data-date="${date}"]`) || dt.cloneNode();
  391. let countDd = dateDt.nextElementSibling || dd.cloneNode();
  392. if(!dateDt.isConnected){
  393. dateDt.classList.remove('template');
  394. countDd.classList.remove('template');
  395. dateDt.dataset.date = dateDt.textContent = date;
  396. if(hasBars){
  397. countDd.style.width = '0px';
  398. dl.insertBefore(dateDt, (i === last) ? dl.lastElementChild.previousElementSibling : dl.querySelector(`dt[data-date="${stats[i + 1].date}"]`));
  399. }else{
  400. dl.insertBefore(dateDt, dl.firstElementChild);
  401. }
  402. dl.insertBefore(countDd, dateDt.nextElementSibling);
  403. }else{
  404. if(dl.dataset.chartKey === chartKey && dl.dataset.max === max && countDd.dataset.count === count && i < last) break;/* it doesn't need update any more. */
  405. }
  406. countDd.title = date + ': ' + count;
  407. countDd.dataset.count = count;
  408. if(i === last - 1){
  409. let label = countDd.querySelector('span') || document.createElement('span');
  410. label.textContent = toMetric(count);
  411. if(!label.isConnected) countDd.appendChild(label);
  412. }
  413. }
  414. dl.dataset.chartKey = chartKey, dl.dataset.max = max;
  415. /* for animation */
  416. animate(function(){
  417. for(let i = 0, dds = dl.querySelectorAll('dd.count:not(.template)'), dd; dd = dds[i]; i++){
  418. dd.style.height = ((dd.dataset.count / max) * 100) + '%';
  419. if(hasBars) dd.style.width = '';
  420. }
  421. });
  422. },
  423. addStyle: function(name = 'style'){
  424. let style = createElement(core.html[name]());
  425. document.head.appendChild(style);
  426. if(elements[name] && elements[name].isConnected) document.head.removeChild(elements[name]);
  427. elements[name] = style;
  428. },
  429. html: {
  430. more: () => `
  431. <button class="more"></button>
  432. `,
  433. tabNavigation: () => `
  434. <nav id="tabNavigation">
  435. <ul>
  436. <li class="template"></li>
  437. </ul>
  438. </nav>
  439. `,
  440. chartSwitcher: () => `
  441. <nav id="chartSwitcher">
  442. <ul>
  443. <li class="template"></li>
  444. </ul>
  445. </nav>
  446. `,
  447. dt: (className, textContent) => `
  448. <dt class="${className}"><span>${textContent}</span></dt>
  449. `,
  450. ddLink: (className, textContent, href, title) => `
  451. <dd class="${className}"><a href="${href}" title="${title}">${textContent}</a></dd>
  452. `,
  453. chart: () => `
  454. <div class="chart">
  455. <dl>
  456. <dt class="template date"></dt>
  457. <dd class="template count"></dd>
  458. </dl>
  459. </div>
  460. `,
  461. style: () => `
  462. <style type="text/css">
  463. /* red scale: 103-206 */
  464. /* gray scale: 119-153-187-221 */
  465. /* coommon */
  466. h2, h3{
  467. margin: 0;
  468. }
  469. ul, ol{
  470. margin: 0;
  471. padding: 0 0 0 2em;
  472. }
  473. a:hover,
  474. a:focus{
  475. color: rgb(206,0,0);
  476. }
  477. .template{
  478. display: none !important;
  479. }
  480. section.text-content{
  481. position: relative;
  482. padding: 0;
  483. }
  484. section.text-content > *{
  485. margin: 14px;
  486. }
  487. section.text-content h2{
  488. text-align: left !important;
  489. margin-bottom: 0;
  490. }
  491. section > header + *{
  492. margin: 0 0 14px !important;
  493. }
  494. button.more{
  495. color: rgb(153,153,153);
  496. border: 1px solid rgb(187,187,187);
  497. background: white;
  498. padding: 0;
  499. cursor: pointer;
  500. }
  501. button.more::-moz-focus-inner{
  502. border: none;
  503. }
  504. button.more::after{
  505. font-size: medium;
  506. content: "▴";
  507. }
  508. .hidden > button.more{
  509. background: rgb(221, 221, 221);
  510. }
  511. .hidden > button.more::after{
  512. content: "▾";
  513. }
  514. /* User panel */
  515. section[data-selector="userSection"] > h2:only-child{
  516. margin-bottom: 14px;/* no content in user panel */
  517. }
  518. section[data-selector="userSection"].hidden{
  519. min-height: 5em;
  520. max-height: 10em;
  521. overflow: hidden;
  522. }
  523. section[data-selector="userSection"] > button.more{
  524. position: relative;
  525. bottom: 0;
  526. width: 100%;
  527. margin: 0;
  528. border: none;
  529. border-top: 1px solid rgba(187, 187, 187);
  530. border-radius: 0 0 5px 5px;
  531. }
  532. section[data-selector="userSection"].hidden > button.more{
  533. position: absolute;
  534. }
  535. /* User Name + Profile */
  536. h2[data-selector="userName"]{
  537. display: flex;
  538. align-items: center;
  539. }
  540. h2[data-selector="userName"] > button.more{
  541. background: rgb(242, 229, 229);
  542. border: 1px solid rgb(230, 221, 214);
  543. border-radius: 5px;
  544. padding: 0 .5em;
  545. margin: 0 .5em;
  546. }
  547. h2[data-selector="userName"].hidden + [data-selector="userProfile"]{
  548. display: none;
  549. }
  550. /* Control panel */
  551. section#control-panel{
  552. font-size: smaller;
  553. width: 200px;
  554. position: absolute;
  555. top: 0;
  556. right: 0;
  557. z-index: 1;
  558. }
  559. section#control-panel h3{
  560. font-size: 1em;
  561. padding: .25em 1em;
  562. border-radius: 5px 5px 0 0;
  563. background: rgb(103, 0, 0);
  564. color: white;
  565. cursor: pointer;
  566. }
  567. section#control-panel.hidden h3{
  568. border-radius: 5px 5px 5px 5px;
  569. }
  570. section#control-panel h3::after{
  571. content: " ▴";
  572. margin-left: .25em;
  573. }
  574. section#control-panel.hidden h3::after{
  575. content: " ▾";
  576. }
  577. ul#user-control-panel{
  578. list-style-type: square;
  579. color: rgb(187, 187, 187);
  580. width: 100%;
  581. margin: .5em 0;
  582. padding: .5em .5em .5em 1.5em;
  583. -webkit-padding-start: 25px;/* ajustment for Chrome */
  584. background: white;
  585. border-radius: 0 0 5px 5px;
  586. border: 1px solid rgb(187, 187, 187);
  587. border-top: none;
  588. box-sizing: border-box;
  589. }
  590. section#control-panel.hidden > ul#user-control-panel{
  591. display: none;
  592. }
  593. /* Discussions on your scripts */
  594. #user-discussions-on-scripts-written{
  595. font-size: 90%;
  596. margin-top: 0;
  597. }
  598. /* tabs */
  599. #tabNavigation{
  600. display: inline-block;
  601. }
  602. #tabNavigation > ul{
  603. list-style-type: none;
  604. padding: 0;
  605. display: flex;
  606. }
  607. #tabNavigation > ul > li{
  608. font-weight: bold;
  609. background: white;
  610. padding: .25em 1em;
  611. border: 1px solid rgb(187, 187, 187);
  612. border-bottom: none;
  613. border-radius: 5px 5px 0 0;
  614. box-shadow: 0 0 5px rgb(221, 221, 221);
  615. }
  616. #tabNavigation > ul > li[data-selected="false"]{
  617. color: rgb(153,153,153);
  618. background: rgb(221, 221, 221);
  619. cursor: pointer;
  620. }
  621. [data-selector="scriptSets"] > section,
  622. [data-tabified] #user-script-list{
  623. border-radius: 0 5px 5px 5px;
  624. }
  625. [data-tabified] header{
  626. display: none;
  627. }
  628. [data-tabified][data-selected="false"]{
  629. display: none;
  630. }
  631. /* Scripts */
  632. [data-selector="scripts"] > div > section > header + p/* no scripts */{
  633. background: white;
  634. border: 1px solid rgb(187, 187, 187);
  635. border-radius: 0 5px 5px 5px;
  636. box-shadow: 0 0 5px rgb(221, 221, 221);
  637. padding: 14px;
  638. }
  639. #user-script-list #codefund/* Supporter/Ad */{
  640. border-bottom: 1px solid rgb(221, 221, 221);
  641. }
  642. #user-script-list #codefund/* Supporter/Ad */ #cf{
  643. position: relative;
  644. }
  645. #user-script-list #codefund/* Supporter/Ad */ span.cf-wrapper{
  646. border-radius: 0 5px 0 0;
  647. }
  648. #user-script-list #codefund/* Supporter/Ad */ a.cf-text > strong,
  649. #user-script-list #codefund/* Supporter/Ad */ a.cf-text > span,
  650. #user-script-list #codefund/* Supporter/Ad */ a.cf-powered-by{
  651. display: inline-block;
  652. transform-origin: bottom left;
  653. }
  654. #user-script-list #codefund/* Supporter/Ad */ a.cf-text > strong{
  655. }
  656. #user-script-list #codefund/* Supporter/Ad */ a.cf-text > span{
  657. font-size: 90%;
  658. transform: scale(1,1.11);
  659. line-height: .90;
  660. }
  661. #user-script-list #codefund/* Supporter/Ad */ a.cf-powered-by{
  662. position: absolute;
  663. bottom: 0;
  664. right: 5px;
  665. line-height: 1.5;
  666. }
  667. #user-script-list li{
  668. padding: .25em 1em;
  669. position: relative;
  670. }
  671. #user-script-list li:last-child{
  672. border-bottom: none;/* missing in gf.qytechs.cn */
  673. }
  674. #user-script-list li article{
  675. position: relative;
  676. z-index: 1;/* over the .chart */
  677. pointer-events: none;
  678. }
  679. #user-script-list li article h2 > a{
  680. margin-right: 4em;/* for preventing from hiding chart's count number */
  681. display: inline-block;
  682. }
  683. #user-script-list li article h2 > a + .script-type{
  684. color: rgb(119, 119, 119);
  685. font-size: 80%;
  686. margin-left: -5em;/* trick */
  687. }
  688. #user-script-list li article h2 > a,
  689. #user-script-list li article h2 > .description/* it's block! */ > span,
  690. #user-script-list li article dl > dt > *,
  691. #user-script-list li article dl > dd > *{
  692. pointer-events: auto;/* apply on inline elements */
  693. }
  694. #user-script-list li button.more{
  695. border-radius: 5px;
  696. position: absolute;
  697. top: 0;
  698. right: 0;
  699. margin: 5px;
  700. width: 2em;
  701. z-index: 1;/* over the .chart */
  702. }
  703. #user-script-list li .description{
  704. font-size: small;
  705. margin: 0 0 0 .1em;/* ajust first letter position */
  706. }
  707. #user-script-list li dl.inline-script-stats{
  708. margin-top: .25em;
  709. column-count: 3;
  710. max-height: 4em;/* Firefox bug? */
  711. }
  712. #user-script-list li dl.inline-script-stats dt{
  713. overflow: hidden;
  714. white-space: nowrap;
  715. text-overflow: ellipsis;
  716. max-width: 200px;/* stretching column mystery on long-lettered languages such as fr-CA */
  717. }
  718. #user-script-list li dl.inline-script-stats .script-list-author{
  719. display: none;
  720. }
  721. #user-script-list li dl.inline-script-stats dd.script-list-version a.update{
  722. padding: 0 .75em 0 .25em;/* enough space for right side */
  723. margin: 0 .25em;
  724. }
  725. #user-script-list li dl.inline-script-stats dt{
  726. width: 55%;
  727. }
  728. #user-script-list li dl.inline-script-stats dd{
  729. width: 45%;
  730. }
  731. #user-script-list li dl.inline-script-stats dt.script-list-daily-installs,
  732. #user-script-list li dl.inline-script-stats dt.script-list-total-installs{
  733. width: 65%;
  734. }
  735. #user-script-list li dl.inline-script-stats dd.script-list-daily-installs,
  736. #user-script-list li dl.inline-script-stats dd.script-list-total-installs{
  737. width: 35%;
  738. }
  739. #user-script-list li.hidden .description,
  740. #user-script-list li.hidden .inline-script-stats{
  741. display: none;
  742. }
  743. /* chartSwitcher */
  744. [data-selector="scripts"] > div > section{
  745. position: relative;/* position anchor */
  746. }
  747. #chartSwitcher{
  748. display: inline-block;
  749. position: absolute;
  750. top: -1.5em;
  751. right: 0;
  752. line-height: 1.25em;
  753. }
  754. #chartSwitcher > ul{
  755. list-style-type: none;
  756. font-size: small;
  757. padding: 0;
  758. margin: 0;
  759. }
  760. #chartSwitcher > ul > li{
  761. color: rgb(187,187,187);
  762. font-weight: bold;
  763. display: inline-block;
  764. border-right: 1px solid rgb(187,187,187);
  765. padding: 0 1em;
  766. margin: 0;
  767. cursor: pointer;
  768. }
  769. #chartSwitcher > ul > li[data-selected="true"]{
  770. color: black;
  771. cursor: auto;
  772. }
  773. #chartSwitcher > ul > li:nth-last-child(2)/* 2nd including template */{
  774. border-right: none;
  775. }
  776. /* chart */
  777. .chart{
  778. position: absolute;
  779. top: 0;
  780. right: 0;
  781. width: 100%;
  782. height: 100%;
  783. overflow: hidden;
  784. mask-image: linear-gradient(to right, rgba(0,0,0,.5), black);
  785. -webkit-mask-image: linear-gradient(to right, rgba(0,0,0,.5), black);
  786. }
  787. .chart > dl{
  788. position: absolute;
  789. bottom: 0;
  790. right: 2em;
  791. margin: 0;
  792. height: calc(100% - 5px);
  793. display: flex;
  794. align-items: flex-end;
  795. }
  796. .chart > dl > dt.date{
  797. display: none;
  798. }
  799. .chart > dl > dd.count{
  800. background: rgb(221,221,221);
  801. border-left: 1px solid white;
  802. margin: 0;
  803. width: 3px;
  804. height: 0%;/* will stretch */
  805. transition: height 250ms ${EASING}, width 250ms ${EASING};
  806. }
  807. .chart > dl > dd.count:nth-last-of-type(3)/* 3rd including template */,
  808. .chart > dl > dd.count:hover{
  809. background: rgb(187,187,187);
  810. }
  811. .chart > dl > dd.count:nth-last-of-type(3):hover{
  812. background: rgb(153,153,153);
  813. }
  814. .chart > dl > dd.count > span{
  815. display: none;/* default */
  816. }
  817. .chart > dl > dd.count:nth-last-of-type(3) > span{
  818. display: inline;/* overwrite */
  819. font-weight: bold;
  820. color: rgb(153,153,153);
  821. position: absolute;
  822. top: 5px;
  823. right: 10px;
  824. pointer-events: none;
  825. }
  826. .chart > dl > dd.count:nth-last-of-type(3)[data-count="0"] > span{
  827. color: rgb(221,221,221);
  828. }
  829. .chart > dl > dd.count:nth-last-of-type(3):hover > span{
  830. color: rgb(119,119,119);
  831. }
  832. /* sidebar */
  833. .sidebar{
  834. padding-top: 0;
  835. }
  836. [data-owner="true"] .ad/* excuse me, it disappears only in my own user page :-) */,
  837. [data-owner="true"] #script-list-filter{
  838. display: none !important;
  839. }
  840. </style>
  841. `,
  842. },
  843. };
  844. class Storage{
  845. static key(key){
  846. return (SCRIPTNAME) ? (SCRIPTNAME + '-' + key) : key;
  847. }
  848. static save(key, value, expire = null){
  849. key = Storage.key(key);
  850. localStorage[key] = JSON.stringify({
  851. value: value,
  852. saved: Date.now(),
  853. expire: expire,
  854. });
  855. }
  856. static read(key){
  857. key = Storage.key(key);
  858. if(localStorage[key] === undefined) return undefined;
  859. let data = JSON.parse(localStorage[key]);
  860. if(data.value === undefined) return data;
  861. if(data.expire === undefined) return data;
  862. if(data.expire === null) return data.value;
  863. if(data.expire < Date.now()) return localStorage.removeItem(key);
  864. return data.value;
  865. }
  866. static delete(key){
  867. key = Storage.key(key);
  868. delete localStorage.removeItem(key);
  869. }
  870. static saved(key){
  871. key = Storage.key(key);
  872. if(localStorage[key] === undefined) return undefined;
  873. let data = JSON.parse(localStorage[key]);
  874. if(data.saved) return data.saved;
  875. else return undefined;
  876. }
  877. }
  878. const $ = function(s){return document.querySelector(s)};
  879. const $$ = function(s){return document.querySelectorAll(s)};
  880. const animate = function(callback, ...params){requestAnimationFrame(() => requestAnimationFrame(() => callback(...params)))};
  881. const wait = function(ms){return new Promise((resolve) => setTimeout(resolve, ms))};
  882. const createElement = function(html){
  883. let outer = document.createElement('div');
  884. outer.innerHTML = html;
  885. return outer.firstElementChild;
  886. };
  887. const toMetric = function(number, fixed = 1){
  888. switch(true){
  889. case(number < 1e3): return (number);
  890. case(number < 1e6): return (number/ 1e3).toFixed(fixed) + 'K';
  891. case(number < 1e9): return (number/ 1e6).toFixed(fixed) + 'M';
  892. case(number < 1e12): return (number/ 1e9).toFixed(fixed) + 'G';
  893. default: return (number/1e12).toFixed(fixed) + 'T';
  894. }
  895. };
  896. const log = function(){
  897. if(!DEBUG) return;
  898. let l = log.last = log.now || new Date(), n = log.now = new Date();
  899. let error = new Error(), line = log.format.getLine(error), callers = log.format.getCallers(error);
  900. //console.log(error.stack);
  901. console.log(
  902. SCRIPTNAME + ':',
  903. /* 00:00:00.000 */ n.toLocaleTimeString() + '.' + n.getTime().toString().slice(-3),
  904. /* +0.000s */ '+' + ((n-l)/1000).toFixed(3) + 's',
  905. /* :00 */ ':' + line,
  906. /* caller.caller */ (callers[2] ? callers[2] + '() => ' : '') +
  907. /* caller */ (callers[1] || '') + '()',
  908. ...arguments
  909. );
  910. };
  911. log.formats = [{
  912. name: 'Firefox Scratchpad',
  913. detector: /MARKER@Scratchpad/,
  914. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1],
  915. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  916. }, {
  917. name: 'Firefox Console',
  918. detector: /MARKER@debugger/,
  919. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1],
  920. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  921. }, {
  922. name: 'Firefox Greasemonkey 3',
  923. detector: /\/gm_scripts\//,
  924. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1],
  925. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  926. }, {
  927. name: 'Firefox Greasemonkey 4+',
  928. detector: /MARKER@user-script:/,
  929. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1] - 500,
  930. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  931. }, {
  932. name: 'Firefox Tampermonkey',
  933. detector: /MARKER@moz-extension:/,
  934. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1] - 6,
  935. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  936. }, {
  937. name: 'Chrome Console',
  938. detector: /at MARKER \(<anonymous>/,
  939. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)$/)[1],
  940. getCallers: (e) => e.stack.match(/[^ ]+(?= \(<anonymous>)/gm),
  941. }, {
  942. name: 'Chrome Tampermonkey',
  943. detector: /at MARKER \((userscript\.html|chrome-extension:)/,
  944. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+)\)$/)[1] - 6,
  945. getCallers: (e) => e.stack.match(/[^ ]+(?= \((userscript\.html|chrome-extension:))/gm),
  946. }, {
  947. name: 'Edge Console',
  948. detector: /at MARKER \(eval/,
  949. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)$/)[1],
  950. getCallers: (e) => e.stack.match(/[^ ]+(?= \(eval)/gm),
  951. }, {
  952. name: 'Edge Tampermonkey',
  953. detector: /at MARKER \(Function/,
  954. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)$/)[1] - 4,
  955. getCallers: (e) => e.stack.match(/[^ ]+(?= \(Function)/gm),
  956. }, {
  957. name: 'Safari',
  958. detector: /^MARKER$/m,
  959. getLine: (e) => 0,/*e.lineが用意されているが最終呼び出し位置のみ*/
  960. getCallers: (e) => e.stack.split('\n'),
  961. }, {
  962. name: 'Default',
  963. detector: /./,
  964. getLine: (e) => 0,
  965. getCallers: (e) => [],
  966. }];
  967. log.format = log.formats.find(function MARKER(f){
  968. if(!f.detector.test(new Error().stack)) return false;
  969. //console.log('//// ' + f.name + '\n' + new Error().stack);
  970. return true;
  971. });
  972. core.initialize();
  973. if(window === top && console.timeEnd) console.timeEnd(SCRIPTNAME);
  974. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址