LWM_ProgressBars

Insert level & skill progress bars to home page & player info page.

当前为 2014-07-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name LWM_ProgressBars
  3. // @description Insert level & skill progress bars to home page & player info page.
  4. // @namespace saturn_hwm
  5. // @author saturn573
  6. // @include http://178.248.235.15/home.php
  7. // @include http://*.lordswm.com/home.php
  8. // @include http://*.heroeswm.ru/home.php
  9. // @include http://178.248.235.15/pl_info.php?id=*
  10. // @include http://*.lordswm.com/pl_info.php?id=*
  11. // @include http://*.heroeswm.ru/pl_info.php?id=*
  12. // @version 0.13
  13. // @grant none
  14.  
  15. var Scales = [
  16. [0, 1500, 4500, 15000, 32000, 90000, 190000, 400000, 860000, 1650000, 3000000, 5000000, 8500000, 14500000, 25000000, 43000000, 70000000, 108000000, 160000000, 230000000, 325000000],
  17. [20, 50, 90, 160, 280, 500, 900, 1600, 2900, 5300, 9600, 17300],
  18. [16, 60, 180, 400, 700, 1200, 2000, 3000, 4300, 6000, 8000, 10500],
  19. [90, 180, 360, 720, 1500, 3000, 5000, 8000, 12000, 17000, 23000, 30000, 38000, 47000],
  20. [10, 30, 60, 100, 150, 210, 280, 360, 450, 550, 660, 800, 1000, 1300, 2000],
  21. [50, 120, 240, 400, 600, 840, 1200, 2000, 3000, 4300, 6000, 8000, 10800, 14000],
  22. [100, 240, 480, 800, 1200, 1680, 2400, 4000, 6000, 8600],
  23. [50, 120, 300, 600, 1000, 1500, 2200, 3000, 4000, 5500, 7800, 11000],
  24. [150, 350, 750, 1400, 2200, 4000],
  25. [30, 80, 165, 310, 555, 970, 1680, 2885, 5770],
  26. [104, 588, 2200, 7000, 10000],
  27. [8, 29, 71, 155, 295, 505, 799, 1191, 1695, 6000, 12000]
  28. ];
  29.  
  30. var factionCount = 9;
  31.  
  32. var Styles = '.pb{ display:inline-block; width:135px; height:16px; background:white; border:2px solid; border-radius: 7px/3px; cursor: pointer; }\
  33. .pb-scale { height: 100%; border-radius: 2px/1px; background:#af9f39; background: linear-gradient(to top, #af9f39, #fffbca); }\
  34. .pb-scale:hover .pb-side-text { opacity: 1; }\
  35. .pb-scale:hover .pb-front-text { opacity: 0; }\
  36. .pb-text { padding-top: 1px; background: initial; overflow: none; position: relative; width: 135px; text-align: center; color: darkgreen; font-size: 12px; font-weight: bold; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }\
  37. .pb-side-text { opacity:0; top: -1px; }\
  38. .pb-front-text { opacity:1; top: -17px; }\
  39. .levelpb { display: inline-flex; margin-left: 10px; width: 180px; } \
  40. .levelpb .pb-side-text { width: 180px; }\
  41. .levelpb .pb-front-text { width: 180px; }\
  42. .skill-table { width: 100%; margin-bottom: 10px; }\
  43. .skill-table caption { text-align: left; }\
  44. .skill-table caption span { float: right; font-size: small; margin-right: 10; }\
  45. .key-column { text-align: left; width: 100%; font-variant: small-caps; }\
  46. .skill-value { font-size: 15px; }\
  47. .skill-value-complete { color: #af9f39; font-size: 20px; font-weight: bold; font-family: "Comic Sans MS", cursive, sans-serif; }\
  48. .skill-value-none { font-weight: normal; }\
  49. .skill-value-low { color: blue; }\
  50. .progress-column { text-align: center; width: 135px; }\
  51. .expander { margin-left: 5px; border-radius: 8px; height: 16px; width: 16px; font-size: 8px; font-weight:bold; background: gold; background: linear-gradient(to top, #af9f39, #fffbca); border: #af9f39; border-style: outset; border-width: 1px; position: relative; top: -3px; }';
  52.  
  53. var expandCaption = '>';
  54. var collapseCaption = '<';
  55. var levelStringRU = '\u0411\u043E\u0435\u0432\u043E\u0439 \u0443\u0440\u043E\u0432\u0435\u043D\u044C';
  56. var factionsGroupTitleRU = '\u0424\u0440\u0430\u043A\u0446\u0438\u044F';
  57. var guildsGroupTitleRU = '\u0413\u0438\u043B\u044C\u0434\u0438\u044F';
  58.  
  59. function round(value, precision)
  60. {
  61. if (precision > 0)
  62. {
  63. var b = precision * 10;
  64. return Math.round(value * b) / b;
  65. }
  66. else
  67. {
  68. return Math.floor(value);
  69. }
  70. }
  71.  
  72. function parseSourceCode(source)
  73. {
  74. var captions = [];
  75. var match;
  76. var cr = /((?:[a-z'\u0430-\u044F\u0451]+\s)?[a-z\u0430-\u044F\u0451]+):\s/gi;
  77. while ((match = cr.exec(source)) != null)
  78. {
  79. captions.push({ Index: cr.lastIndex, Value: match[0].toString() });
  80. }
  81. var getCaption = function(index)
  82. {
  83. for (var ii = captions.length - 1; ii>= 0; ii--)
  84. {
  85. if (captions[ii].Index < index)
  86. {
  87. return captions[ii].Value;
  88. }
  89. }
  90. return null;
  91. }
  92. var result = [];
  93. var sr = /(?:\s|>)(\d+)(<\/b>|<\/a>)?\s\((\d+(?:\.\d+)?)\)/g;
  94. while((match = sr.exec(source)) != null)
  95. {
  96. result.push({
  97. Caption: getCaption(sr.lastIndex),
  98. Level: +match[1].toString(),
  99. Score: +match[3].toString(),
  100. Sign: match[2]
  101. });
  102. }
  103. return result;
  104. }
  105. function addStyles()
  106. {
  107. var style = document.createElement('style');
  108. style.type = 'text/css';
  109. style.appendChild(document.createTextNode(Styles));
  110. document.head.appendChild(style);
  111. }
  112.  
  113. function checkScale(scale)
  114. {
  115. if (scale && scale.length > 0)
  116. {
  117. if (scale.length > 1)
  118. {
  119. for (var ii = 1; ii < scale.length; ii++)
  120. {
  121. if (scale[ii] <= scale[ii - 1])
  122. {
  123. return false;
  124. }
  125. }
  126. }
  127. return true;
  128. }
  129. }
  130.  
  131. function createProgressBar(points, left, percentage)
  132. {
  133. var border = document.createElement('div');
  134. border.className = 'pb';
  135. var scale = document.createElement('div');
  136. scale.className = 'pb-scale';
  137. scale.style.width = percentage.toFixed(0) + '%';
  138. var valueDiv = document.createElement('div');
  139. valueDiv.appendChild(document.createTextNode(points));
  140. valueDiv.className = 'pb-text pb-side-text';
  141. var l = document.createElement('span');
  142. l.style.fontSize = 'smaller';
  143. l.appendChild(document.createTextNode('+' + left));
  144. valueDiv.appendChild(l);
  145. scale.appendChild(valueDiv);
  146. var percentageDiv = document.createElement('div');
  147. percentageDiv.className = 'pb-text pb-front-text';
  148. percentageDiv.appendChild(document.createTextNode(scale.style.width));
  149. scale.appendChild(percentageDiv);
  150. border.appendChild(scale);
  151. return border;
  152. }
  153.  
  154. function getScoreRange(score, scale)
  155. {
  156. if (!checkScale(scale))
  157. {
  158. return;
  159. }
  160. var initialValue = 0;
  161. var finalValue = score;
  162. var level = 0;
  163. for (var ii = 0; ii < scale.length; ii++)
  164. {
  165. if (score >= scale[ii])
  166. {
  167. initialValue = scale[ii];
  168. }
  169. else
  170. {
  171. finalValue = scale[ii];
  172. level = ii;
  173. break;
  174. }
  175. }
  176. return { Initial: initialValue, Final: finalValue, Level: level };
  177. }
  178.  
  179. function getProgressPercentage(range, score)
  180. {
  181. if (range)
  182. {
  183. return (score - range.Initial) * 100 / (range.Final - range.Initial);
  184. }
  185. return 0;
  186. }
  187.  
  188. function getScale(index)
  189. {
  190. return Scales[index];
  191. }
  192.  
  193. function getCaption(value, exclude)
  194. {
  195. if (exclude)
  196. {
  197. var r = new RegExp(exclude, 'i');
  198. return value.Caption.replace(r, '');
  199. }
  200. return value.Caption;
  201. }
  202.  
  203. function createRow(value, scaleIndex, excludeCaption)
  204. {
  205. var scale = getScale(scaleIndex);
  206. var range = getScoreRange(value.Score, scale);
  207. var row = document.createElement('tr');
  208. var c1 = document.createElement('td');
  209. c1.className = 'key-column';
  210. if (scaleIndex == 1 && value.Sign)
  211. {
  212. c1.style = 'font-weight: bold; text-decoration:underline; ';
  213. }
  214. c1.appendChild(document.createTextNode(getCaption(value, excludeCaption)));
  215. var lb = document.createElement('b');
  216. lb.className = 'skill-value';
  217. lb.appendChild(document.createTextNode(value.Level));
  218. if (value.Score >= range.Final)
  219. {
  220. lb.className = 'skill-value-complete';
  221. }
  222. else if (!value.Score)
  223. {
  224. lb.className = 'skill-value-none';
  225. }
  226. c1.appendChild(lb);
  227. row.appendChild(c1);
  228. var c2 = document.createElement('td');
  229. c2.className = 'progress-column';
  230. if (value.Score == 0)
  231. {
  232. c2.appendChild(document.createTextNode('-'));
  233. }
  234. else if (value.Score >= range.Final)
  235. {
  236. c2.appendChild(document.createTextNode(value.Score));
  237. }
  238. else
  239. {
  240. var percentage = getProgressPercentage(range, value.Score);
  241. var points = value.Score;
  242. var left = round(range.Final - value.Score, 1);
  243. if (range.Level > value.Level)
  244. {
  245. percentage = 100;
  246. left = '0.1';
  247. var rl = document.createElement('small');
  248. rl.innerHTML = - (range.Level - value.Level);
  249. lb.className = 'skill-value-low';
  250. c1.appendChild(rl);
  251. }
  252. var pb = createProgressBar(points, left, percentage);
  253. c2.appendChild(pb);
  254. }
  255. row.appendChild(c2);
  256. return row;
  257. }
  258.  
  259. function createExpanderButton()
  260. {
  261. var cb = document.createElement('input');
  262. cb.type = 'button';
  263. cb.value = expandCaption;
  264. cb.className = 'expander';
  265. cb.collapsed = true;
  266. cb.onclick = function(event)
  267. {
  268. var r = this.parentNode.parentNode;
  269. var display = this.collapsed ? '' : 'none';
  270. r.nextSibling.style.display = display;
  271. r.nextSibling.nextSibling.style.display = display;
  272. r.nextSibling.nextSibling.nextSibling.style.display = display;
  273. this.collapsed = !this.collapsed;
  274. this.value = this.collapsed ? expandCaption : collapseCaption;
  275. };
  276. return cb;
  277. }
  278.  
  279. function insertExpander(table)
  280. {
  281. var row = table.lastChild;
  282. for (var ii = 0; ii < 3; ii++)
  283. {
  284. row.firstChild.style = 'padding-left: 15px;';
  285. row.style.display = 'none';
  286. row = row.previousSibling;
  287. }
  288. row.firstChild.appendChild(createExpanderButton());
  289. }
  290.  
  291. function getScaleIndex(index)
  292. {
  293. if (index < factionCount)
  294. {
  295. return 1;
  296. }
  297. var result = index - factionCount + 2;
  298. if (result >= Scales.length)
  299. {
  300. result = Scales.length - 1;
  301. }
  302. return result;
  303. }
  304.  
  305. function isEn()
  306. {
  307. return /^www\.lordswm\.com/.test(location.host);
  308. }
  309.  
  310. function createSkillTable(caption)
  311. {
  312. var result = document.createElement('table');
  313. result.className = 'skill-table';
  314. var cpt = document.createElement('caption');
  315. cpt.appendChild(document.createTextNode(caption));
  316. result.appendChild(cpt);
  317. return result;
  318. }
  319.  
  320. function replaceSkills()
  321. {
  322. var home = document.getElementById('home_2');
  323. if (home)
  324. {
  325. var mainNode = home.parentNode;
  326. var items = parseSourceCode(mainNode.innerHTML.toString());
  327. var range = document.createRange();
  328. range.selectNodeContents(mainNode);
  329. range.deleteContents();
  330. range.detach();
  331. var t = createSkillTable(isEn() ? 'Factions' : factionsGroupTitleRU);
  332. var excludeCaption;
  333. var ii = 0;
  334. var factionPoints = 0;
  335. do
  336. {
  337. if (ii < factionCount)
  338. {
  339. factionPoints += items[ii].Score
  340. }
  341. t.appendChild(createRow(items[ii], getScaleIndex(ii), excludeCaption));
  342. ii++;
  343. if (ii == factionCount)
  344. {
  345. var sum = document.createElement('span');
  346. sum.appendChild(document.createTextNode(' \u03A3'));
  347. var sub = document.createElement('sub');
  348. sub.appendChild(document.createTextNode(isEn() ? 'all' : 'общ.'));
  349. sum.appendChild(sub);
  350. sum.appendChild(document.createTextNode('= ' + round(factionPoints, 2)));
  351. t.firstChild.appendChild(sum);
  352. mainNode.appendChild(t);
  353. t = createSkillTable(isEn() ? 'Guilds' : guildsGroupTitleRU);
  354. excludeCaption = "('\\sguild)|(" + guildsGroupTitleRU + ')';
  355. }
  356. }
  357. while (ii < items.length - 2);
  358. insertExpander(t);
  359. mainNode.appendChild(t);
  360. }
  361. }
  362.  
  363. function getLevelPoints(points)
  364. {
  365. var r = /\(([\d\.]+)\)(?:\s\+(-?[\d\.]+))?/;
  366. var m = r.exec(points)
  367. if (m)
  368. {
  369. return { Points: m[1], Left: m[2] }
  370. }
  371. }
  372.  
  373. function insertLevelUpProgressBar()
  374. {
  375. var bs= document.getElementsByTagName('b');
  376. var lbReg = new RegExp('(?:Combat\\slevel|' + levelStringRU + '):\\s(\\d+)');
  377. for (var ii = 0; ii < bs.length; ii++)
  378. {
  379. var b = bs[ii];
  380. var m = lbReg.exec(b.innerHTML);
  381. if (m)
  382. {
  383. var start = b.nextSibling;
  384. var end = start;
  385. do
  386. {
  387. end = end.nextSibling;
  388. }
  389. while (end && (!end.tagName || end.tagName.toLowerCase() != 'br'));
  390. var next = end.nextSibling;
  391. if (end)
  392. {
  393. var pointsText;
  394. var range = document.createRange();
  395. range.setStart(start, 0);
  396. range.setEnd(end, 0);
  397. pointsText = range.toString();
  398. var lvl = getLevelPoints(range.toString());
  399. if (lvl)
  400. {
  401. var r = getScoreRange(lvl.Points, getScale(0));
  402. if (r && r.Final > lvl.Points)
  403. {
  404. var percentage = getProgressPercentage(r, lvl.Points);
  405. if (r.Level > m[1])
  406. {
  407. b.appendChild(document.createTextNode('+'));
  408. percentage = 100;
  409. }
  410. var pb = createProgressBar(lvl.Points, lvl.Left, percentage);
  411. pb.className += ' levelpb';
  412. b.parentNode.insertBefore(pb, b.nextSibling);
  413. range.deleteContents();
  414. }
  415. }
  416. range.detach();
  417. break;
  418. }
  419. }
  420. }
  421. }
  422.  
  423. function main()
  424. {
  425. addStyles();
  426. insertLevelUpProgressBar();
  427. replaceSkills();
  428. }
  429.  
  430. main();
  431.  
  432. // ==/UserScript==

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址