GreasyFork User Dashboard

It redesigns user pages to improve the browsability.

目前為 2019-12-27 提交的版本,檢視 最新版本

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