GreasyFork User Dashboard

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

当前为 2020-03-05 提交的版本,查看 最新版本

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