GreasyFork User Dashboard

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

目前为 2020-06-04 提交的版本。查看 最新版本

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