GreasyFork User Dashboard

It redesigns user pages to improve the browsability.

当前为 2020-01-11 提交的版本,查看 最新版本

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