GreasyFork User Dashboard

It redesigns user pages to improve the browsability.

目前为 2019-04-05 提交的版本,查看 最新版本

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