GreasyFork User Dashboard

为 Greasy Fork 提供一个新的列表用户页面。

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

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