Greasy Fork 还支持 简体中文。

GreasyFork User Dashboard

It redesigns user pages.

目前為 2019-03-18 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name GreasyFork User Dashboard
  3. // @name:ja GreasyFork User Dashboard
  4. // @namespace knoa.jp
  5. // @description It redesigns user pages.
  6. // @description:ja 新しいユーザーページを提供します。
  7. // @include https://greasyfork.org/*/users/*
  8. // @version 1.3.0
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function(){
  13. const SCRIPTNAME = 'GreasyForkUserDashboard';
  14. const DEBUG = false;/*
  15. [update] 1.3.0
  16. Now it can hide the profile text of your own page.
  17.  
  18. [bug]
  19.  
  20. [to do]
  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)'),
  47. scripts: () => $('body > header + div > div:nth-of-type(1)'),
  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. let more = createElement(core.html.more()), props = site.get.props(li), key = li.dataset.scriptName, isLibrary = li.dataset.scriptType === 'library';
  267. if(!storages.shown[key]) li.classList.add('hidden');
  268. more.addEventListener('click', function(e){
  269. li.classList.toggle('hidden');
  270. if(li.classList.contains('hidden')) delete storages.shown[key];/* prevent from getting fat storage */
  271. else storages.shown[key] = true;
  272. Storage.save('shown', storages.shown);
  273. });
  274. li.dataset.scriptUrl = props.name.href;
  275. li.appendChild(more);
  276. if(isLibrary) continue;/* not so critical to skip below by continue */
  277. /* attatch titles */
  278. props.dailyInstalls.previousElementSibling.title = props.dailyInstalls.previousElementSibling.textContent;
  279. props.totalInstalls.previousElementSibling.title = props.totalInstalls.previousElementSibling.textContent;
  280. props.ratings.previousElementSibling.title = props.ratings.previousElementSibling.textContent;
  281. props.createdDate.previousElementSibling.title = props.createdDate.previousElementSibling.textContent;
  282. props.updatedDate.previousElementSibling.title = props.updatedDate.previousElementSibling.textContent;
  283. /* wrap the description to make it an inline element */
  284. let span = document.createElement('span');
  285. span.textContent = props.description.textContent.trim();
  286. props.description.replaceChild(span, props.description.firstChild);
  287. /* Link to Code */
  288. let versionLabel = createElement(core.html.dt('script-list-version', translation.version));
  289. let versionDd = createElement(core.html.ddLink('script-list-version', props.scriptVersion, props.name.href + '/code', translation.code));
  290. versionLabel.title = versionLabel.textContent;
  291. props.stats.insertBefore(versionLabel, props.createdDate.previousElementSibling);
  292. props.stats.insertBefore(versionDd, props.createdDate.previousElementSibling);
  293. /* Link to Version up */
  294. if(elements.controlPanel){
  295. let updateLink = document.createElement('a');
  296. updateLink.href = props.name.href + '/versions/new';
  297. updateLink.textContent = UPDATELINKTEXT;
  298. updateLink.title = translation.update;
  299. updateLink.classList.add('update');
  300. versionDd.appendChild(updateLink);
  301. }
  302. /* Link to Stats from Total installs */
  303. let statsDd = createElement(core.html.ddLink('script-list-total-installs', props.totalInstalls.textContent, props.name.href + '/stats', translation.stats));
  304. props.stats.replaceChild(statsDd, props.totalInstalls);
  305. /* Link to History from Updated date */
  306. let historyDd = createElement(core.html.ddLink('script-list-updated-date', props.updatedDate.textContent, props.name.href + '/versions', translation.history));
  307. props.stats.replaceChild(historyDd, props.updatedDate);
  308. }
  309. },
  310. addChartSwitcher: function(){
  311. let userScriptList = elements.userScriptList;
  312. if(!userScriptList) return;
  313. const keys = [
  314. {label: translation.installs, selector: 'installs'},
  315. {label: translation.updateChecks, selector: 'updateChecks'},
  316. ];
  317. let nav = createElement(core.html.chartSwitcher());
  318. let template = nav.querySelector('li.template');
  319. userScriptList.parentNode.appendChild(nav);/* less affected on dom */
  320. for(let i = 0; keys[i]; i++){
  321. let li = template.cloneNode(true);
  322. li.classList.remove('template');
  323. li.textContent = keys[i].label;
  324. li.dataset.key = keys[i].selector;
  325. li.addEventListener('click', function(e){
  326. li.parentNode.querySelector('[data-selected="true"]').dataset.selected = 'false';
  327. li.dataset.selected = 'true';
  328. storages.chartKey = li.dataset.key;
  329. Storage.save('chartKey', storages.chartKey);
  330. core.drawCharts();
  331. });
  332. if(keys[i].selector === storages.chartKey) li.dataset.selected = 'true';
  333. else li.dataset.selected = 'false';
  334. template.parentNode.insertBefore(li, template);
  335. }
  336. core.drawCharts();
  337. },
  338. drawCharts: function(){
  339. let promises = [];
  340. if(timers.charts && timers.charts.length) timers.charts.forEach((id) => clearTimeout(id));/* stop all the former timers */
  341. timers.charts = [];
  342. for(let i = 0, list = elements.userScriptList, li; li = list.children[i]; i++){
  343. if(li.dataset.scriptType === 'library') continue;
  344. /* Draw chart of daily update checks */
  345. let chart = li.querySelector('.chart') || createElement(core.html.chart()), key = li.dataset.scriptName;
  346. if(storages.stats[key] && storages.stats[key].data){
  347. timers.charts[i] = setTimeout(function(){
  348. core.drawChart(chart, storages.stats[key].data.slice(-DAYS));
  349. if(!chart.isConnected) li.appendChild(chart);
  350. }, i * DRAWINGDELAY);/* CPU friendly */
  351. }
  352. let now = Date.now(), updated = (storages.stats[key]) ? storages.stats[key].updated || 0 : 0, past = updated % STATSUPDATE, expire = updated - past + STATSUPDATE;
  353. if(now < expire) continue;/* still up-to-date */
  354. promises.push(new Promise(function(resolve, reject){
  355. timers.charts[i] = setTimeout(function(){
  356. fetch(li.dataset.scriptUrl + '/stats.csv', {credentials: 'include'}/* for sensitive scripts */)/* less file size than json */
  357. .then(response => response.text())
  358. .then(csv => {
  359. let lines = csv.split('\n');
  360. lines = lines.slice(1, -1);/* cut the labels + blank line */
  361. storages.stats[key] = {data: [], updated: now};
  362. for(let i = 0; lines[i]; i++){
  363. let p = lines[i].split(',');
  364. storages.stats[key].data[i] = {
  365. date: p[0],
  366. installs: parseInt(p[1]),
  367. updateChecks: parseInt(p[2]),
  368. };
  369. }
  370. core.drawChart(chart, storages.stats[key].data.slice(-DAYS));
  371. if(!chart.isConnected) li.appendChild(chart);
  372. resolve();
  373. });
  374. }, i * INTERVAL);/* server friendly */
  375. }));
  376. }
  377. if(promises.length) Promise.all(promises).then((values) => Storage.save('stats', storages.stats));
  378. },
  379. drawChart: function(chart, stats){
  380. let dl = chart.querySelector('dl'), dt = dl.querySelector('dt.template'), dd = dl.querySelector('dd.template'), hasBars = (2 < dl.children.length);
  381. let chartKey = storages.chartKey, max = Math.max(DEFAULTMAX, ...stats.map(s => s[chartKey]));
  382. for(let i = last = stats.length - 1; stats[i]; i--){/* from last */
  383. let date = stats[i].date, count = stats[i][chartKey];
  384. let dateDt = dl.querySelector(`dt[data-date="${date}"]`) || dt.cloneNode();
  385. let countDd = dateDt.nextElementSibling || dd.cloneNode();
  386. if(!dateDt.isConnected){
  387. dateDt.classList.remove('template');
  388. countDd.classList.remove('template');
  389. dateDt.dataset.date = dateDt.textContent = date;
  390. if(hasBars){
  391. countDd.style.width = '0px';
  392. dl.insertBefore(dateDt, (i === last) ? dl.lastElementChild.previousElementSibling : dl.querySelector(`dt[data-date="${stats[i + 1].date}"]`));
  393. }else{
  394. dl.insertBefore(dateDt, dl.firstElementChild);
  395. }
  396. dl.insertBefore(countDd, dateDt.nextElementSibling);
  397. }else{
  398. if(dl.dataset.chartKey === chartKey && dl.dataset.max === max && countDd.dataset.count === count && i < last) break;/* it doesn't need update any more. */
  399. }
  400. countDd.title = date + ': ' + count;
  401. countDd.dataset.count = count;
  402. if(i === last - 1){
  403. let label = countDd.querySelector('span') || document.createElement('span');
  404. label.textContent = toMetric(count);
  405. if(!label.isConnected) countDd.appendChild(label);
  406. }
  407. }
  408. dl.dataset.chartKey = chartKey, dl.dataset.max = max;
  409. /* for animation */
  410. animate(function(){
  411. for(let i = 0, dds = dl.querySelectorAll('dd.count:not(.template)'), dd; dd = dds[i]; i++){
  412. dd.style.height = ((dd.dataset.count / max) * 100) + '%';
  413. if(hasBars) dd.style.width = '';
  414. }
  415. });
  416. },
  417. addStyle: function(name = 'style'){
  418. let style = createElement(core.html[name]());
  419. document.head.appendChild(style);
  420. if(elements[name] && elements[name].isConnected) document.head.removeChild(elements[name]);
  421. elements[name] = style;
  422. },
  423. html: {
  424. more: () => `
  425. <button class="more"></button>
  426. `,
  427. tabNavigation: () => `
  428. <nav id="tabNavigation">
  429. <ul>
  430. <li class="template"></li>
  431. </ul>
  432. </nav>
  433. `,
  434. chartSwitcher: () => `
  435. <nav id="chartSwitcher">
  436. <ul>
  437. <li class="template"></li>
  438. </ul>
  439. </nav>
  440. `,
  441. dt: (className, textContent) => `
  442. <dt class="${className}"><span>${textContent}</span></dt>
  443. `,
  444. ddLink: (className, textContent, href, title) => `
  445. <dd class="${className}"><a href="${href}" title="${title}">${textContent}</a></dd>
  446. `,
  447. chart: () => `
  448. <div class="chart">
  449. <dl>
  450. <dt class="template date"></dt>
  451. <dd class="template count"></dd>
  452. </dl>
  453. </div>
  454. `,
  455. style: () => `
  456. <style type="text/css">
  457. /* red scale: 103-206 */
  458. /* gray scale: 119-153-187-221 */
  459. /* coommon */
  460. h2, h3{
  461. margin: 0;
  462. }
  463. ul, ol{
  464. margin: 0;
  465. padding: 0 0 0 2em;
  466. }
  467. a:hover,
  468. a:focus{
  469. color: rgb(206,0,0);
  470. }
  471. .template{
  472. display: none !important;
  473. }
  474. section.text-content{
  475. position: relative;
  476. padding: 0;
  477. }
  478. section.text-content > *{
  479. margin: 14px;
  480. }
  481. section.text-content h2{
  482. text-align: left !important;
  483. margin-bottom: 0;
  484. }
  485. section > header + *{
  486. margin: 0 0 14px !important;
  487. }
  488. button.more{
  489. color: rgb(153,153,153);
  490. border: 1px solid rgb(187,187,187);
  491. background: white;
  492. padding: 0;
  493. cursor: pointer;
  494. }
  495. button.more::-moz-focus-inner{
  496. border: none;
  497. }
  498. button.more::after{
  499. font-size: medium;
  500. content: "▴";
  501. }
  502. .hidden > button.more{
  503. background: rgb(221, 221, 221);
  504. }
  505. .hidden > button.more::after{
  506. content: "▾";
  507. }
  508. /* User panel */
  509. section[data-selector="userSection"] > h2:only-child{
  510. margin-bottom: 14px;/* no content in user panel */
  511. }
  512. section[data-selector="userSection"].hidden{
  513. min-height: 5em;
  514. max-height: 10em;
  515. overflow: hidden;
  516. }
  517. section[data-selector="userSection"] > button.more{
  518. position: relative;
  519. bottom: 0;
  520. width: 100%;
  521. margin: 0;
  522. border: none;
  523. border-top: 1px solid rgba(187, 187, 187);
  524. border-radius: 0 0 5px 5px;
  525. }
  526. section[data-selector="userSection"].hidden > button.more{
  527. position: absolute;
  528. }
  529. /* User Name + Profile */
  530. h2[data-selector="userName"]{
  531. display: flex;
  532. align-items: center;
  533. }
  534. h2[data-selector="userName"] > button.more{
  535. background: rgb(242, 229, 229);
  536. border: 1px solid rgb(230, 221, 214);
  537. border-radius: 5px;
  538. padding: 0 .5em;
  539. margin: 0 .5em;
  540. }
  541. h2[data-selector="userName"].hidden + [data-selector="userProfile"]{
  542. display: none;
  543. }
  544. /* Control panel */
  545. section#control-panel{
  546. font-size: smaller;
  547. width: 200px;
  548. position: absolute;
  549. top: 0;
  550. right: 0;
  551. z-index: 1;
  552. }
  553. section#control-panel h3{
  554. font-size: 1em;
  555. padding: .25em 1em;
  556. border-radius: 5px 5px 0 0;
  557. background: rgb(103, 0, 0);
  558. color: white;
  559. cursor: pointer;
  560. }
  561. section#control-panel.hidden h3{
  562. border-radius: 5px 5px 5px 5px;
  563. }
  564. section#control-panel h3::after{
  565. content: " ▴";
  566. margin-left: .25em;
  567. }
  568. section#control-panel.hidden h3::after{
  569. content: " ▾";
  570. }
  571. ul#user-control-panel{
  572. list-style-type: square;
  573. color: rgb(187, 187, 187);
  574. width: 100%;
  575. margin: .5em 0;
  576. padding: .5em .5em .5em 1.5em;
  577. -webkit-padding-start: 25px;/* ajustment for Chrome */
  578. background: white;
  579. border-radius: 0 0 5px 5px;
  580. border: 1px solid rgb(187, 187, 187);
  581. border-top: none;
  582. box-sizing: border-box;
  583. }
  584. section#control-panel.hidden > ul#user-control-panel{
  585. display: none;
  586. }
  587. /* Discussions on your scripts */
  588. #user-discussions-on-scripts-written{
  589. margin-top: 0;
  590. }
  591. /* tabs */
  592. #tabNavigation{
  593. display: inline-block;
  594. }
  595. #tabNavigation > ul{
  596. list-style-type: none;
  597. padding: 0;
  598. display: flex;
  599. }
  600. #tabNavigation > ul > li{
  601. font-weight: bold;
  602. background: white;
  603. padding: .25em 1em;
  604. border: 1px solid rgb(187, 187, 187);
  605. border-bottom: none;
  606. border-radius: 5px 5px 0 0;
  607. box-shadow: 0 0 5px rgb(221, 221, 221);
  608. }
  609. #tabNavigation > ul > li[data-selected="false"]{
  610. color: rgb(153,153,153);
  611. background: rgb(221, 221, 221);
  612. cursor: pointer;
  613. }
  614. [data-selector="scriptSets"] > section,
  615. [data-tabified] #user-script-list{
  616. border-radius: 0 5px 5px 5px;
  617. }
  618. [data-tabified] header{
  619. display: none;
  620. }
  621. [data-tabified][data-selected="false"]{
  622. display: none;
  623. }
  624. /* Scripts */
  625. [data-selector="scripts"] > div > section > header + p/* no scripts */{
  626. background: white;
  627. border: 1px solid rgb(187, 187, 187);
  628. border-radius: 0 5px 5px 5px;
  629. box-shadow: 0 0 5px rgb(221, 221, 221);
  630. padding: 14px;
  631. }
  632. #user-script-list li{
  633. padding: .25em 1em;
  634. position: relative;
  635. }
  636. #user-script-list li:last-child{
  637. border-bottom: none;/* missing in greasyfork.org */
  638. }
  639. #user-script-list li article{
  640. position: relative;
  641. z-index: 1;/* over the .chart */
  642. pointer-events: none;
  643. }
  644. #user-script-list li article h2 > a{
  645. margin-right: 4em;/* for preventing from hiding chart's count number */
  646. display: inline-block;
  647. }
  648. #user-script-list li article h2 > a + .script-type{
  649. margin-left: -4em;/* trick */
  650. }
  651. #user-script-list li article h2 > a,
  652. #user-script-list li article h2 > .description/* it's block! */ > span,
  653. #user-script-list li article dl > dt > *,
  654. #user-script-list li article dl > dd > *{
  655. pointer-events: auto;/* apply on inline elements */
  656. }
  657. #user-script-list li button.more{
  658. border-radius: 5px;
  659. position: absolute;
  660. top: 0;
  661. right: 0;
  662. margin: 5px;
  663. width: 2em;
  664. z-index: 1;/* over the .chart */
  665. }
  666. #user-script-list li .description{
  667. font-size: small;
  668. margin: 0 0 0 .1em;/* ajust first letter position */
  669. }
  670. #user-script-list li dl.inline-script-stats{
  671. margin-top: .25em;
  672. column-count: 3;
  673. max-height: 4em;/* Firefox bug? */
  674. }
  675. #user-script-list li dl.inline-script-stats dt{
  676. overflow: hidden;
  677. white-space: nowrap;
  678. text-overflow: ellipsis;
  679. max-width: 200px;/* stretching column mystery on long-lettered languages such as fr-CA */
  680. }
  681. #user-script-list li dl.inline-script-stats .script-list-author{
  682. display: none;
  683. }
  684. #user-script-list li dl.inline-script-stats dd.script-list-version a.update{
  685. padding: 0 .75em 0 .25em;/* enough space for right side */
  686. margin: 0 .25em;
  687. }
  688. #user-script-list li dl.inline-script-stats dt{
  689. width: 55%;
  690. }
  691. #user-script-list li dl.inline-script-stats dd{
  692. width: 45%;
  693. }
  694. #user-script-list li dl.inline-script-stats dt.script-list-daily-installs,
  695. #user-script-list li dl.inline-script-stats dt.script-list-total-installs{
  696. width: 65%;
  697. }
  698. #user-script-list li dl.inline-script-stats dd.script-list-daily-installs,
  699. #user-script-list li dl.inline-script-stats dd.script-list-total-installs{
  700. width: 35%;
  701. }
  702. #user-script-list li.hidden .description,
  703. #user-script-list li.hidden .inline-script-stats{
  704. display: none;
  705. }
  706. /* chartSwitcher */
  707. [data-selector="scripts"] > div > section{
  708. position: relative;/* position anchor */
  709. }
  710. #chartSwitcher{
  711. display: inline-block;
  712. position: absolute;
  713. top: -1.5em;
  714. right: 0;
  715. line-height: 1.25em;
  716. }
  717. #chartSwitcher > ul{
  718. list-style-type: none;
  719. font-size: small;
  720. padding: 0;
  721. margin: 0;
  722. }
  723. #chartSwitcher > ul > li{
  724. color: rgb(187,187,187);
  725. font-weight: bold;
  726. display: inline-block;
  727. border-right: 1px solid rgb(187,187,187);
  728. padding: 0 1em;
  729. margin: 0;
  730. cursor: pointer;
  731. }
  732. #chartSwitcher > ul > li[data-selected="true"]{
  733. color: black;
  734. cursor: auto;
  735. }
  736. #chartSwitcher > ul > li:nth-last-child(2)/* 2nd including template */{
  737. border-right: none;
  738. }
  739. /* chart */
  740. .chart{
  741. position: absolute;
  742. top: 0;
  743. right: 0;
  744. width: 100%;
  745. height: 100%;
  746. overflow: hidden;
  747. mask-image: linear-gradient(to right, rgba(0,0,0,.5), black);
  748. -webkit-mask-image: linear-gradient(to right, rgba(0,0,0,.5), black);
  749. }
  750. .chart > dl{
  751. position: absolute;
  752. bottom: 0;
  753. right: 2em;
  754. margin: 0;
  755. height: calc(100% - 5px);
  756. display: flex;
  757. align-items: flex-end;
  758. }
  759. .chart > dl > dt.date{
  760. display: none;
  761. }
  762. .chart > dl > dd.count{
  763. background: rgb(221,221,221);
  764. border-left: 1px solid white;
  765. margin: 0;
  766. width: 3px;
  767. height: 0%;/* will stretch */
  768. transition: height 250ms ${EASING}, width 250ms ${EASING};
  769. }
  770. .chart > dl > dd.count:nth-last-of-type(3)/* 3rd including template */,
  771. .chart > dl > dd.count:hover{
  772. background: rgb(187,187,187);
  773. }
  774. .chart > dl > dd.count:nth-last-of-type(3):hover{
  775. background: rgb(153,153,153);
  776. }
  777. .chart > dl > dd.count > span{
  778. display: none;/* default */
  779. }
  780. .chart > dl > dd.count:nth-last-of-type(3) > span{
  781. display: inline;/* overwrite */
  782. font-weight: bold;
  783. color: rgb(153,153,153);
  784. position: absolute;
  785. top: 5px;
  786. right: 10px;
  787. pointer-events: none;
  788. }
  789. .chart > dl > dd.count:nth-last-of-type(3)[data-count="0"] > span{
  790. color: rgb(221,221,221);
  791. }
  792. .chart > dl > dd.count:nth-last-of-type(3):hover > span{
  793. color: rgb(119,119,119);
  794. }
  795. /* sidebar */
  796. .sidebar{
  797. padding-top: 0;
  798. }
  799. [data-owner="true"] .ad/* excuse me, it disappears only in my own user page :-) */,
  800. [data-owner="true"] #script-list-filter{
  801. display: none !important;
  802. }
  803. </style>
  804. `,
  805. },
  806. };
  807. class Storage{
  808. static key(key){
  809. return (SCRIPTNAME) ? (SCRIPTNAME + '-' + key) : key;
  810. }
  811. static save(key, value, expire = null){
  812. key = Storage.key(key);
  813. localStorage[key] = JSON.stringify({
  814. value: value,
  815. saved: Date.now(),
  816. expire: expire,
  817. });
  818. }
  819. static read(key){
  820. key = Storage.key(key);
  821. if(localStorage[key] === undefined) return undefined;
  822. let data = JSON.parse(localStorage[key]);
  823. if(data.value === undefined) return data;
  824. if(data.expire === undefined) return data;
  825. if(data.expire === null) return data.value;
  826. if(data.expire < Date.now()) return localStorage.removeItem(key);
  827. return data.value;
  828. }
  829. static delete(key){
  830. key = Storage.key(key);
  831. delete localStorage.removeItem(key);
  832. }
  833. static saved(key){
  834. key = Storage.key(key);
  835. if(localStorage[key] === undefined) return undefined;
  836. let data = JSON.parse(localStorage[key]);
  837. if(data.saved) return data.saved;
  838. else return undefined;
  839. }
  840. }
  841. const $ = function(s){return document.querySelector(s)};
  842. const $$ = function(s){return document.querySelectorAll(s)};
  843. const animate = function(callback, ...params){requestAnimationFrame(() => requestAnimationFrame(() => callback(...params)))};
  844. const wait = function(ms){return new Promise((resolve) => setTimeout(resolve, ms))};
  845. const createElement = function(html){
  846. let outer = document.createElement('div');
  847. outer.innerHTML = html;
  848. return outer.firstElementChild;
  849. };
  850. const toMetric = function(number, fixed = 1){
  851. switch(true){
  852. case(number < 1e3): return (number);
  853. case(number < 1e6): return (number/ 1e3).toFixed(fixed) + 'K';
  854. case(number < 1e9): return (number/ 1e6).toFixed(fixed) + 'M';
  855. case(number < 1e12): return (number/ 1e9).toFixed(fixed) + 'G';
  856. default: return (number/1e12).toFixed(fixed) + 'T';
  857. }
  858. };
  859. const log = function(){
  860. if(!DEBUG) return;
  861. let l = log.last = log.now || new Date(), n = log.now = new Date();
  862. let error = new Error(), line = log.format.getLine(error), callers = log.format.getCallers(error);
  863. //console.log(error.stack);
  864. console.log(
  865. SCRIPTNAME + ':',
  866. /* 00:00:00.000 */ n.toLocaleTimeString() + '.' + n.getTime().toString().slice(-3),
  867. /* +0.000s */ '+' + ((n-l)/1000).toFixed(3) + 's',
  868. /* :00 */ ':' + line,
  869. /* caller.caller */ (callers[2] ? callers[2] + '() => ' : '') +
  870. /* caller */ (callers[1] || '') + '()',
  871. ...arguments
  872. );
  873. };
  874. log.formats = [{
  875. name: 'Firefox Scratchpad',
  876. detector: /MARKER@Scratchpad/,
  877. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1],
  878. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  879. }, {
  880. name: 'Firefox Console',
  881. detector: /MARKER@debugger/,
  882. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1],
  883. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  884. }, {
  885. name: 'Firefox Greasemonkey 3',
  886. detector: /\/gm_scripts\//,
  887. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1],
  888. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  889. }, {
  890. name: 'Firefox Greasemonkey 4+',
  891. detector: /MARKER@user-script:/,
  892. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1] - 500,
  893. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  894. }, {
  895. name: 'Firefox Tampermonkey',
  896. detector: /MARKER@moz-extension:/,
  897. getLine: (e) => e.stack.split('\n')[1].match(/([0-9]+):[0-9]+$/)[1] - 6,
  898. getCallers: (e) => e.stack.match(/^[^@]*(?=@)/gm),
  899. }, {
  900. name: 'Chrome Console',
  901. detector: /at MARKER \(<anonymous>/,
  902. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)$/)[1],
  903. getCallers: (e) => e.stack.match(/[^ ]+(?= \(<anonymous>)/gm),
  904. }, {
  905. name: 'Chrome Tampermonkey',
  906. detector: /at MARKER \((userscript\.html|chrome-extension:)/,
  907. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+)\)$/)[1] - 6,
  908. getCallers: (e) => e.stack.match(/[^ ]+(?= \((userscript\.html|chrome-extension:))/gm),
  909. }, {
  910. name: 'Edge Console',
  911. detector: /at MARKER \(eval/,
  912. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)$/)[1],
  913. getCallers: (e) => e.stack.match(/[^ ]+(?= \(eval)/gm),
  914. }, {
  915. name: 'Edge Tampermonkey',
  916. detector: /at MARKER \(Function/,
  917. getLine: (e) => e.stack.split('\n')[2].match(/([0-9]+):[0-9]+\)$/)[1] - 4,
  918. getCallers: (e) => e.stack.match(/[^ ]+(?= \(Function)/gm),
  919. }, {
  920. name: 'Safari',
  921. detector: /^MARKER$/m,
  922. getLine: (e) => 0,/*e.lineが用意されているが最終呼び出し位置のみ*/
  923. getCallers: (e) => e.stack.split('\n'),
  924. }, {
  925. name: 'Default',
  926. detector: /./,
  927. getLine: (e) => 0,
  928. getCallers: (e) => [],
  929. }];
  930. log.format = log.formats.find(function MARKER(f){
  931. if(!f.detector.test(new Error().stack)) return false;
  932. //console.log('//// ' + f.name + '\n' + new Error().stack);
  933. return true;
  934. });
  935. core.initialize();
  936. if(window === top && console.timeEnd) console.timeEnd(SCRIPTNAME);
  937. })();