Greasy Fork 支持简体中文。

IITC plugin: Cell score graph plugin

Cell score graph plugin

  1. // ==UserScript==
  2. // @name IITC plugin: Cell score graph plugin
  3. // @version 0.0.1
  4. // @author Odr1ck
  5. // @description Cell score graph plugin
  6. // @match https://*.ingress.com/*
  7. // @match http://*.ingress.com/*
  8. // @match https://*.ingress.com/mission/*
  9. // @match http://*.ingress.com/mission/*
  10. // @id iitc-plugin-cell-score
  11. // @category Misc
  12. // @license MIT
  13. // @include https://*.ingress.com/*
  14. // @include http://*.ingress.com/*
  15. // @include https://*.ingress.com/mission/*
  16. // @include http://*.ingress.com/mission/*
  17. // @grant none
  18. // @namespace https://greasyfork.org/users/410740
  19. // ==/UserScript==
  20.  
  21. /******/ (function(modules) { // webpackBootstrap
  22. /******/ // The module cache
  23. /******/ var installedModules = {};
  24. /******/
  25. /******/ // The require function
  26. /******/ function __webpack_require__(moduleId) {
  27. /******/
  28. /******/ // Check if module is in cache
  29. /******/ if(installedModules[moduleId]) {
  30. /******/ return installedModules[moduleId].exports;
  31. /******/ }
  32. /******/ // Create a new module (and put it into the cache)
  33. /******/ var module = installedModules[moduleId] = {
  34. /******/ i: moduleId,
  35. /******/ l: false,
  36. /******/ exports: {}
  37. /******/ };
  38. /******/
  39. /******/ // Execute the module function
  40. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  41. /******/
  42. /******/ // Flag the module as loaded
  43. /******/ module.l = true;
  44. /******/
  45. /******/ // Return the exports of the module
  46. /******/ return module.exports;
  47. /******/ }
  48. /******/
  49. /******/
  50. /******/ // expose the modules object (__webpack_modules__)
  51. /******/ __webpack_require__.m = modules;
  52. /******/
  53. /******/ // expose the module cache
  54. /******/ __webpack_require__.c = installedModules;
  55. /******/
  56. /******/ // define getter function for harmony exports
  57. /******/ __webpack_require__.d = function(exports, name, getter) {
  58. /******/ if(!__webpack_require__.o(exports, name)) {
  59. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  60. /******/ }
  61. /******/ };
  62. /******/
  63. /******/ // define __esModule on exports
  64. /******/ __webpack_require__.r = function(exports) {
  65. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  66. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  67. /******/ }
  68. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  69. /******/ };
  70. /******/
  71. /******/ // create a fake namespace object
  72. /******/ // mode & 1: value is a module id, require it
  73. /******/ // mode & 2: merge all properties of value into the ns
  74. /******/ // mode & 4: return value when already ns object
  75. /******/ // mode & 8|1: behave like require
  76. /******/ __webpack_require__.t = function(value, mode) {
  77. /******/ if(mode & 1) value = __webpack_require__(value);
  78. /******/ if(mode & 8) return value;
  79. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  80. /******/ var ns = Object.create(null);
  81. /******/ __webpack_require__.r(ns);
  82. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  83. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  84. /******/ return ns;
  85. /******/ };
  86. /******/
  87. /******/ // getDefaultExport function for compatibility with non-harmony modules
  88. /******/ __webpack_require__.n = function(module) {
  89. /******/ var getter = module && module.__esModule ?
  90. /******/ function getDefault() { return module['default']; } :
  91. /******/ function getModuleExports() { return module; };
  92. /******/ __webpack_require__.d(getter, 'a', getter);
  93. /******/ return getter;
  94. /******/ };
  95. /******/
  96. /******/ // Object.prototype.hasOwnProperty.call
  97. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  98. /******/
  99. /******/ // __webpack_public_path__
  100. /******/ __webpack_require__.p = "";
  101. /******/
  102. /******/
  103. /******/ // Load entry module and return exports
  104. /******/ return __webpack_require__(__webpack_require__.s = 2);
  105. /******/ })
  106. /************************************************************************/
  107. /******/ ([
  108. /* 0 */
  109. /***/ (function(module, exports, __webpack_require__) {
  110.  
  111.  
  112. var result = __webpack_require__(4);
  113.  
  114. if (result && result.__esModule) {
  115. result = result.default;
  116. }
  117.  
  118. if (typeof result === "string") {
  119. module.exports = result;
  120. } else {
  121. module.exports = result.toString();
  122. }
  123.  
  124. /***/ }),
  125. /* 1 */
  126. /***/ (function(module, exports, __webpack_require__) {
  127.  
  128.  
  129. var result = __webpack_require__(5);
  130.  
  131. if (result && result.__esModule) {
  132. result = result.default;
  133. }
  134.  
  135. if (typeof result === "string") {
  136. module.exports = result;
  137. } else {
  138. module.exports = result.toString();
  139. }
  140.  
  141. /***/ }),
  142. /* 2 */
  143. /***/ (function(module, exports, __webpack_require__) {
  144.  
  145. module.exports = __webpack_require__(3);
  146.  
  147.  
  148. /***/ }),
  149. /* 3 */
  150. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  151.  
  152. "use strict";
  153. __webpack_require__.r(__webpack_exports__);
  154. /* harmony import */ var _ui_main_html__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
  155. /* harmony import */ var _ui_main_html__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_ui_main_html__WEBPACK_IMPORTED_MODULE_0__);
  156. /* harmony import */ var _ui_main_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
  157. /* harmony import */ var _ui_main_css__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_ui_main_css__WEBPACK_IMPORTED_MODULE_1__);
  158.  
  159.  
  160.  
  161. function wrapper(plugin_info) {
  162. if (typeof window.plugin !== 'function') window.plugin = function () {};
  163. plugin_info.buildName = 'Cell Score';
  164. plugin_info.dateTimeVersion = '20220013115848';
  165. plugin_info.pluginId = 'iitc-plugin-cell-score';
  166. var e = {};
  167. var logo = new Image();
  168. logo.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFoAAABaAQMAAAACZtNBAAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAAaNJREFUOMuV1EFq6zAQBuAReqAuHk8XENU13iJU18pOzqqXCPQqMl30FKUKvcBANyqoUkeayHLponQCcT6L8MfxL8MPY/Zwe9RlfpY1Tui3NGHXMuHpNUZksGFApb8KB3S8k3mLXOpSBoqo0V1jZVYVdWQotDWrxLDBn73II7IYOsGRRSajkWNl0tHQG3KkCwZo+RoJBhzHVpEJtseKrJBAYYGANhLoXAOtE8CLjgINbm14TXxRlw7skIzQIX5EbbPucbrCf8P4jqPDBIIsAzaBzhsKuA2arvw4oB4ueeK+Ig7Ita4TwZ/igKA7FzagmQA0atlw/AoNGw7G7nG74ebWHP4M/Lfm8G8ga3O0J8ZjUuejvjCeojqjfGe8BPmM8MGovbCekUHUAJaBHYqReskZlwLgF6pzQ/SEcbdbG1zrVkNSCHdUZ02gPrXuaK5s65Pp3aJpfbpp3eLy6sjdoqFj4oa18X2X+KXDUY09t5Iby33lLr9RnRkUW2nxCr9Ubj/vDMeRHGsU7ndjnFubfucGx5E8+jVNyIoT7X+b478+Q34zn/dfSp2/U9a6AAAAAElFTkSuQmCC";
  169. var dialogID = "cell-score-ui";
  170. var canvasID = "cell-score-canvas";
  171. var canvasWidth = 960;
  172. var canvasHeight = 500;
  173. var EPOCH = 1389150000000;
  174. var CYCLE_LENGTH = 630000000;
  175. var CHECKPOINT_LENGTH = 18000000; ////////////////////////////////////////
  176.  
  177. e.toggleBox = function () {
  178. var scale = 0.58;
  179. var html = "<canvas width=\"".concat(canvasWidth, "\" height=\"").concat(canvasHeight, "\" id=\"").concat(canvasID, "\" style=\"width: ").concat(canvasWidth * scale, "px; height: ").concat(canvasHeight * scale, "px\"></canvas>");
  180. dialog({
  181. html: html,
  182. title: 'Cell score',
  183. width: "auto",
  184. id: dialogID
  185. });
  186. var center = window.map.getCenter();
  187. latE6 = Math.floor(center.lat * 1e6);
  188. lngE6 = Math.floor(center.lng * 1e6);
  189. window.postAjax('getRegionScoreDetails', {
  190. latE6: latE6,
  191. lngE6: lngE6
  192. }, draw);
  193. };
  194.  
  195. var getCurrentCycleNumber = function getCurrentCycleNumber() {
  196. return Math.floor((Date.now() - EPOCH) / CYCLE_LENGTH);
  197. };
  198.  
  199. var getCycleNumber = function getCycleNumber(date) {
  200. return Math.floor((date.getTime() - EPOCH) / CYCLE_LENGTH);
  201. };
  202.  
  203. var getCurrentCycle = function getCurrentCycle() {
  204. var timezone = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  205. var cycle = getCurrentCycleNumber();
  206. return calcCycle(cycle, timezone);
  207. };
  208.  
  209. var calcCycle = function calcCycle(cycle) {
  210. var timezone = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  211. var start = new Date();
  212. var currentOffest = start.getTimezoneOffset();
  213. var diff = currentOffest - timezone * 60 * -1;
  214. diff = diff * 60 * 1000;
  215. var now = start.getTime();
  216. var localNow = new Date(now + diff);
  217. var cycleDisplay = cycle + 1;
  218. start.setTime(EPOCH + cycle * CYCLE_LENGTH);
  219. year = start.getFullYear();
  220. start.setTime(start.getTime() + CHECKPOINT_LENGTH);
  221. var checkpoints = [];
  222. var naturalCheckpoints = [];
  223. var nextCp = null;
  224.  
  225. for (var i = 0; i < 35; i++) {
  226. var next = isNext(start, now);
  227. var d = new Date(start.getTime() + diff);
  228. var item = {
  229. id: i,
  230. year: d.getFullYear(),
  231. month: d.getMonth() + 1,
  232. date: d.getDate(),
  233. hours: d.getHours(),
  234. minutes: d.getMinutes(),
  235. day: d.getDay(),
  236. status: next ? 'next' : start.getTime() < now ? 'past' : 'upcoming',
  237. "final": i == 34,
  238. fake: false,
  239. diff: d.getTime() - localNow.getTime(),
  240. next: next
  241. };
  242. if (next) nextCp = item;
  243. checkpoints.push(item);
  244. naturalCheckpoints.push(item);
  245.  
  246. if (d.getHours() === 0) {
  247. var last = checkpoints.pop();
  248.  
  249. var _d = new Date(start.getTime() - 60000 + diff);
  250.  
  251. checkpoints.push({
  252. id: i,
  253. year: _d.getFullYear(),
  254. month: _d.getMonth() + 1,
  255. date: _d.getDate(),
  256. hours: 24,
  257. minutes: 0,
  258. day: _d.getDay(),
  259. status: last.status,
  260. "final": last["final"],
  261. fake: true,
  262. diff: last.diff,
  263. next: last.next
  264. });
  265. checkpoints.push(last);
  266. }
  267.  
  268. start.setTime(start.getTime() + CHECKPOINT_LENGTH);
  269. }
  270.  
  271. if (year > 2014) {
  272. var yearEnd = new Date(year - 1, 11, 31, 23, 59);
  273. var lastCycle = Math.floor((yearEnd.getTime() - EPOCH) / CYCLE_LENGTH);
  274. cycleDisplay = cycle - lastCycle;
  275. }
  276.  
  277. if (cycleDisplay < 10) {
  278. cycleDisplay = '0' + cycleDisplay;
  279. }
  280.  
  281. return {
  282. cycle: year + '.' + cycleDisplay,
  283. cycleId: parseInt(cycleDisplay),
  284. checkpoints: checkpoints,
  285. naturalCheckpoints: naturalCheckpoints,
  286. nextCheckPoint: nextCp,
  287. localDate: {
  288. year: localNow.getFullYear(),
  289. month: localNow.getMonth() + 1,
  290. date: localNow.getDate(),
  291. hours: localNow.getHours(),
  292. minutes: localNow.getMinutes(),
  293. day: localNow.getDay()
  294. }
  295. };
  296. };
  297.  
  298. var isNext = function isNext(start, now) {
  299. return start.getTime() > now && now + CHECKPOINT_LENGTH > start.getTime();
  300. };
  301.  
  302. var draw = function draw(data) {
  303. var date = new Date();
  304. var cycleData = getCurrentCycle(-(date.getTimezoneOffset() / 60));
  305. var width = canvasWidth;
  306. var height = canvasHeight;
  307. var resColor = '#3b8bff';
  308. var enlColor = '#03e500';
  309. var fontFamily = '-apple-system,BlinkMacSystemFont,Roboto,Helvetica,Arial,sans-serif';
  310. var cns = $("#".concat(canvasID))[0];
  311. var ctx = cns.getContext('2d');
  312. ctx.fillStyle = "#000000";
  313. ctx.fillRect(0, 0, width, height);
  314. var leftSpace = 70;
  315. var rightSpace = 20;
  316. var topSpace = 110;
  317. var bottomSpace = 40;
  318. var cw = (width - leftSpace - rightSpace) / 35;
  319. ctx.lineWidth = 1;
  320. ctx.strokeStyle = "#818181";
  321. var cpPoints = [];
  322.  
  323. for (var c = 0; c < 35; c++) {
  324. var x = Math.floor(leftSpace + c * cw + 5);
  325. cpPoints[c] = x;
  326. ctx.beginPath();
  327. ctx.moveTo(x, topSpace);
  328. ctx.lineTo(x, height - bottomSpace);
  329. ctx.stroke();
  330. ctx.save();
  331. ctx.translate(x, height - bottomSpace + 15);
  332. ctx.rotate(-Math.PI / 4);
  333. ctx.fillStyle = '#ffffff';
  334. ctx.font = "bold 14px " + fontFamily;
  335. ctx.textAlign = "center";
  336. ctx.textBaseline = "middle";
  337. ctx.fillText(c + 1 + '', 0, 0);
  338. ctx.restore();
  339. }
  340.  
  341. var score = data.result.scoreHistory.sort(function (a, b) {
  342. var av = parseInt(a[0]);
  343. var bv = parseInt(b[0]);
  344. if (av > bv) return 1;
  345. if (av < bv) return -1;
  346. return 0;
  347. });
  348. var max = Number.MIN_VALUE;
  349.  
  350. for (var i = 0; i < score.length; i++) {
  351. var item = score[i];
  352. item[0] = parseInt(item[0]);
  353. item[1] = parseInt(item[1]);
  354. item[2] = parseInt(item[2]);
  355. if (item[1] > max) max = item[1];
  356. if (item[2] > max) max = item[2];
  357. }
  358.  
  359. var maxPoints = [100, 200, 400, 600, 800];
  360. var mult = 1;
  361. var maxFinded = false;
  362. var newMax = 0;
  363.  
  364. while (!maxFinded) {
  365. for (var _i = 0; _i < maxPoints.length; _i++) {
  366. var val = maxPoints[_i];
  367. var mv = val * mult;
  368.  
  369. if (mv >= max) {
  370. newMax = mv;
  371. maxFinded = true;
  372. break;
  373. }
  374. }
  375.  
  376. mult *= 10;
  377. }
  378.  
  379. max = newMax;
  380. var h = height - topSpace - bottomSpace - 20;
  381. var cnt = 5;
  382. var ch = Math.floor(h / (cnt - 1));
  383. var yStep = max / (cnt - 1);
  384.  
  385. function formatYVal(val) {
  386. if (val < 1000) return val;else if (val < 1000000) return val / 1000 + "K";else return val / 1000000 + "M";
  387. }
  388.  
  389. for (var _c = cnt - 1; _c >= 0; _c--) {
  390. var y = _c * ch + topSpace + 10;
  391. ctx.beginPath();
  392. ctx.moveTo(leftSpace - 10, y);
  393. ctx.lineTo(width - rightSpace, y);
  394. ctx.stroke();
  395. ctx.fillStyle = '#ffffff';
  396. ctx.font = "bold 14px " + fontFamily;
  397. ctx.textAlign = "right";
  398. ctx.textBaseline = "middle";
  399. var yv = formatYVal((cnt - _c - 1) * yStep);
  400. ctx.fillText(yv + '', leftSpace - 20, y);
  401. }
  402.  
  403. function drawLine(ix) {
  404. var color = '#ffffff';
  405. ctx.lineWidth = 3;
  406. if (ix == 1) color = enlColor;
  407. if (ix == 2) color = resColor;
  408. ctx.strokeStyle = color;
  409. ctx.fillStyle = color;
  410. var points = [];
  411. ctx.beginPath();
  412.  
  413. for (var _i2 = 0; _i2 < score.length; _i2++) {
  414. var _x = cpPoints[_i2];
  415.  
  416. var _y = h - h * (score[_i2][ix] / max) + topSpace + 10;
  417.  
  418. points.push({
  419. x: _x,
  420. y: _y
  421. });
  422. if (_i2 == 0) ctx.moveTo(_x, _y);else ctx.lineTo(_x, _y);
  423. }
  424.  
  425. ctx.stroke();
  426.  
  427. for (var _i3 = 0; _i3 < points.length; _i3++) {
  428. ctx.beginPath();
  429. ctx.arc(points[_i3].x, points[_i3].y, 5, 0, Math.PI * 2);
  430. ctx.fill();
  431. }
  432. }
  433.  
  434. function padNumber(val) {
  435. val = val + '';
  436. if (val.length < 3) return val;
  437. var parts = [];
  438.  
  439. while (val.length > 3) {
  440. parts.unshift(val.substr(val.length - 3));
  441. val = val.substr(0, val.length - 3);
  442. }
  443.  
  444. if (val) parts.unshift(val);
  445. return parts.join(',');
  446. }
  447.  
  448. function zeroPad(val) {
  449. if (val >= 10) return val + '';
  450. return '0' + val;
  451. }
  452.  
  453. drawLine(1);
  454. drawLine(2);
  455. ctx.fillStyle = '#d4ab75';
  456. ctx.font = "bold 20px " + fontFamily;
  457. ctx.textAlign = "left";
  458. ctx.textBaseline = "middle";
  459. ctx.fillText(data.result.regionName, 30, 20);
  460.  
  461. if (cycleData) {
  462. ctx.fillStyle = '#ffffff';
  463. ctx.font = "bold 18px " + fontFamily;
  464. ctx.fillText(cycleData.cycle + '.' + score.length, 30, 45);
  465. ctx.fillStyle = '#cccccc';
  466. ctx.font = "bold 14px " + fontFamily;
  467. var localDate = zeroPad(cycleData.localDate.date) + '.' + zeroPad(cycleData.localDate.month) + '.' + cycleData.localDate.year;
  468. localDate += ' ';
  469. localDate += zeroPad(cycleData.localDate.hours) + ':' + zeroPad(cycleData.localDate.minutes);
  470. ctx.fillText(localDate, 30, 80);
  471. }
  472.  
  473. var tw = width * 0.9 / 5; /////////////////////
  474.  
  475. ctx.fillStyle = '#ffffff';
  476. ctx.font = "18px " + fontFamily;
  477. ctx.fillText('Счет:', tw + leftSpace, 20);
  478. ctx.fillStyle = enlColor;
  479. ctx.font = "18px " + fontFamily;
  480. ctx.fillText(padNumber(data.result.gameScore[0]), tw + leftSpace, 45);
  481. ctx.fillStyle = resColor;
  482. ctx.font = "18px " + fontFamily;
  483. ctx.fillText(padNumber(data.result.gameScore[1]), tw + leftSpace, 68); /////////////////////
  484.  
  485. ctx.fillStyle = '#ffffff';
  486. ctx.font = "18px " + fontFamily;
  487. ctx.fillText('Отсечка:', tw * 2 + leftSpace, 20);
  488. ctx.fillStyle = enlColor;
  489. ctx.font = "18px " + fontFamily;
  490. ctx.fillText(padNumber(score[score.length - 1][1]), tw * 2 + leftSpace, 45);
  491. ctx.fillStyle = resColor;
  492. ctx.font = "18px " + fontFamily;
  493. ctx.fillText(padNumber(score[score.length - 1][2]), tw * 2 + leftSpace, 68); /////////////////////
  494.  
  495. ctx.fillStyle = '#ffffff';
  496. ctx.font = "18px " + fontFamily;
  497. ctx.fillText('Топ:', tw * 3 + leftSpace, 20);
  498.  
  499. for (var _i4 = 0; _i4 < data.result.topAgents.length; _i4++) {
  500. var _item = data.result.topAgents[_i4];
  501. ctx.fillStyle = _item.team === 'RESISTANCE' ? resColor : enlColor;
  502. ctx.font = "18px " + fontFamily;
  503. ctx.fillText(_item.nick, tw * 3 + leftSpace, 45 + _i4 * 23);
  504. }
  505.  
  506. ctx.drawImage(logo, width - 140, 10);
  507. }; ////////////////////////////////////////
  508.  
  509.  
  510. window.plugin.cellScore = e;
  511.  
  512. function setup() {
  513. $('<style>').prop('type', 'text/css').html(plugin_info.css).appendTo('head');
  514. $('body').append(plugin_info.ui);
  515. $('#toolbox').append('<a onclick="window.plugin.cellScore.toggleBox();return false;">Cell Score</a>');
  516. }
  517.  
  518. setup.info = plugin_info;
  519. if (!window.bootPlugins) window.bootPlugins = [];
  520. window.bootPlugins.push(setup);
  521. if (window.iitcLoaded && typeof setup === 'function') setup();
  522. }
  523.  
  524. var script = document.createElement('script');
  525. var info = {};
  526. info.ui = _ui_main_html__WEBPACK_IMPORTED_MODULE_0___default.a;
  527. info.css = _ui_main_css__WEBPACK_IMPORTED_MODULE_1___default.a;
  528.  
  529. if (typeof GM_info !== 'undefined' && GM_info && GM_info.script) {
  530. info.script = {
  531. version: GM_info.script.version,
  532. name: GM_info.script.name,
  533. description: GM_info.script.description
  534. };
  535. }
  536.  
  537. var textContent = document.createTextNode('(' + wrapper + ')(' + JSON.stringify(info) + ')');
  538. script.appendChild(textContent);
  539. (document.body || document.head || document.documentElement).appendChild(script);
  540.  
  541. /***/ }),
  542. /* 4 */
  543. /***/ (function(module, exports) {
  544.  
  545. module.exports = "";
  546.  
  547. /***/ }),
  548. /* 5 */
  549. /***/ (function(module, exports, __webpack_require__) {
  550.  
  551. // Imports
  552. var ___CSS_LOADER_API_IMPORT___ = __webpack_require__(6);
  553. exports = ___CSS_LOADER_API_IMPORT___(false);
  554. // Module
  555. exports.push([module.i, "", ""]);
  556. // Exports
  557. module.exports = exports;
  558.  
  559.  
  560. /***/ }),
  561. /* 6 */
  562. /***/ (function(module, exports, __webpack_require__) {
  563.  
  564. "use strict";
  565.  
  566.  
  567. /*
  568. MIT License http://www.opensource.org/licenses/mit-license.php
  569. Author Tobias Koppers @sokra
  570. */
  571. // css base code, injected by the css-loader
  572. // eslint-disable-next-line func-names
  573. module.exports = function (useSourceMap) {
  574. var list = []; // return the list of modules as css string
  575.  
  576. list.toString = function toString() {
  577. return this.map(function (item) {
  578. var content = cssWithMappingToString(item, useSourceMap);
  579.  
  580. if (item[2]) {
  581. return "@media ".concat(item[2], " {").concat(content, "}");
  582. }
  583.  
  584. return content;
  585. }).join('');
  586. }; // import a list of modules into the list
  587. // eslint-disable-next-line func-names
  588.  
  589.  
  590. list.i = function (modules, mediaQuery, dedupe) {
  591. if (typeof modules === 'string') {
  592. // eslint-disable-next-line no-param-reassign
  593. modules = [[null, modules, '']];
  594. }
  595.  
  596. var alreadyImportedModules = {};
  597.  
  598. if (dedupe) {
  599. for (var i = 0; i < this.length; i++) {
  600. // eslint-disable-next-line prefer-destructuring
  601. var id = this[i][0];
  602.  
  603. if (id != null) {
  604. alreadyImportedModules[id] = true;
  605. }
  606. }
  607. }
  608.  
  609. for (var _i = 0; _i < modules.length; _i++) {
  610. var item = [].concat(modules[_i]);
  611.  
  612. if (dedupe && alreadyImportedModules[item[0]]) {
  613. // eslint-disable-next-line no-continue
  614. continue;
  615. }
  616.  
  617. if (mediaQuery) {
  618. if (!item[2]) {
  619. item[2] = mediaQuery;
  620. } else {
  621. item[2] = "".concat(mediaQuery, " and ").concat(item[2]);
  622. }
  623. }
  624.  
  625. list.push(item);
  626. }
  627. };
  628.  
  629. return list;
  630. };
  631.  
  632. function cssWithMappingToString(item, useSourceMap) {
  633. var content = item[1] || ''; // eslint-disable-next-line prefer-destructuring
  634.  
  635. var cssMapping = item[3];
  636.  
  637. if (!cssMapping) {
  638. return content;
  639. }
  640.  
  641. if (useSourceMap && typeof btoa === 'function') {
  642. var sourceMapping = toComment(cssMapping);
  643. var sourceURLs = cssMapping.sources.map(function (source) {
  644. return "/*# sourceURL=".concat(cssMapping.sourceRoot || '').concat(source, " */");
  645. });
  646. return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
  647. }
  648.  
  649. return [content].join('\n');
  650. } // Adapted from convert-source-map (MIT)
  651.  
  652.  
  653. function toComment(sourceMap) {
  654. // eslint-disable-next-line no-undef
  655. var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))));
  656. var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64);
  657. return "/*# ".concat(data, " */");
  658. }
  659.  
  660. /***/ })
  661. /******/ ]);