GreasyFork User Dashboard

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

目前为 2020-01-28 提交的版本。查看 最新版本

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