GreasyFork User Dashboard

It redesigns user pages to improve the browsability.

目前為 2020-04-18 提交的版本,檢視 最新版本

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