GreasyFork User Dashboard

It redesigns user pages.

当前为 2019-03-16 提交的版本,查看 最新版本

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