GreasyFork User Dashboard

It redesigns user pages to improve the browsability.

当前为 2019-12-27 提交的版本,查看 最新版本

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