GreasyFork User Dashboard

为 Greasy Fork 提供一个一览性出色的新用户页面。

当前为 2020-07-26 提交的版本,查看 最新版本

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