SHARE
TWEET

Untitled

a guest Nov 19th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Quest Pinner
  3. // @version      0.9
  4. // @description  Dodatek przypinajÄ…cy quest do chatu w grze
  5. // @author       Akechi
  6. // @match        http://*.margonem.pl/
  7. // @grant        none
  8. // ==/UserScript==
  9.  
  10. ((Engine, API, $) => {
  11. 'use strict';
  12.  
  13. let pinnedQuests = {};
  14. const lsName = "addon_PinQuests/list";
  15. const chatQuests = $(`<div class="pinned-quests" />`);
  16.  
  17. $("body").append(`
  18. <style>
  19. .pin-quest-bck {
  20. background: url(../img/gui/buttony.png?v=6) no-repeat -497px -396px;
  21. width:16px;
  22. height:16px;
  23. top: 4px;
  24. left: 4px;
  25. position: absolute;
  26. }
  27. .pinned-quests {
  28. margin-bottom: .7em;
  29. position: relative;
  30. z-index: 0;
  31. order:2;
  32. }
  33. .pinned-quests > p {
  34. border-bottom: 1px solid #526543;
  35. padding: .5em .4em .3em;
  36. box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.75);
  37. position: relative;
  38. }
  39. .pinned-quests > p:before {
  40. content: '';
  41. display: block;
  42. position: absolute;
  43. z-index: -1;
  44. background-color: rgba(95, 0, 200, 0.25);
  45. width: 100%;
  46. height: 100%;
  47. top: 0;
  48. left: 0;
  49. }
  50. .pinned-quests b {
  51. display:block;
  52. color: #d0ff48;
  53. margin-bottom: .2em;
  54. }
  55. .pinned-quests .q_kill {
  56. display: block;
  57. }
  58. .pinned-quests .q_kill > .red {
  59. color: #f16462;
  60. }
  61. .left-column .messages-wrapper .scroll-pane {
  62.     display: flex;
  63.     flex-direction: column;
  64. }
  65. .left-column .messages-wrapper .scroll-pane > .chat-message {
  66. order:1;
  67. }
  68. </style>
  69. `);
  70.  
  71. this.detectQuestsWindowInit = () => {
  72. const self = this;
  73. let questsObj;
  74.  
  75. Object.defineProperty(Engine, 'quests', {
  76. set(value) {
  77. questsObj = value;
  78.  
  79. if(value !== false) {
  80. self.hookQuestBox();
  81. }
  82. },
  83. get () { return questsObj; }
  84. });
  85. }
  86.  
  87. this.hookQuestBox = () => {
  88. const _showDetails = Engine.quests.showDetails;
  89.  
  90. Engine.quests.showDetails = (...args) => {
  91. this.addPinButton(args);
  92. return _showDetails.apply(this, args);
  93. }
  94. }
  95.  
  96. this.addPinButton = (quest) => {
  97. const [buttons, , id] = quest;
  98. const btn = API.Templates.get('button').addClass("small").append(`<div class="pin-quest-bck" />`);
  99. btn.find(".label").css("visibility", "hidden").html("0");
  100. this.updateButton(id, btn);
  101. buttons.push(
  102. btn.on("click", () => {
  103. this.pinQuest(id);
  104. this.updateButton(id, btn);
  105. })
  106. );
  107. }
  108.  
  109. this.updateButton = (id, button) => { //call after change in Storage
  110. if(this.isPinned(id)) {
  111. button.removeClass("green").addClass("red").tip("Odepnij questa");
  112. } else {
  113. button.removeClass("red").addClass("green").tip("Przypnij questa");
  114. }
  115. }
  116.  
  117. this.isPinned = id => (pinnedQuests[id] === undefined ? false : pinnedQuests[id]);
  118.  
  119. this.pinQuest = (id) => {
  120. pinnedQuests[id] = !this.isPinned(id);
  121. API.Storage.set(lsName, pinnedQuests);
  122. this.refreshQuests();
  123. }
  124.  
  125. this.getPinnedQuests = () => {
  126. return Object.keys(pinnedQuests).filter(id => pinnedQuests[id] ? true : false);
  127. }
  128.  
  129. this.getQuests = () => {
  130. return new Promise((resolve, reject) => {
  131. $.post(`engine?t=quests${Engine.communication.prepareUrl()}`, (e) => {
  132. if (e.quests !== undefined)
  133. resolve(e.quests);
  134. else
  135. reject(`There is not information about quests`);
  136. });
  137. });
  138. }
  139.  
  140. const $window = $(window);
  141. this.refreshQuests = () => {
  142. this.getQuests()
  143. .then(quests => {
  144. this.reWriteQuests(quests);
  145. }).then(()=>{
  146. Engine.chat.setScrollOnBottom();
  147. $window.resize();
  148. });
  149. }
  150.  
  151. this.reWriteQuests = (quests) => {
  152. const pinnedQuests = this.getPinnedQuests();
  153. const startedQuests = $(quests);
  154. chatQuests.empty();
  155.  
  156. for(const id of pinnedQuests) {
  157. for (const stertedQuest of startedQuests) {
  158. const temp = $(stertedQuest);
  159.  
  160. if(id == temp.data('quest-id')) {
  161. const title = stertedQuest.firstChild.textContent;
  162. $(stertedQuest.firstChild).remove();
  163. this.colorKillWord(stertedQuest);
  164.  
  165. chatQuests.append(
  166. temp.prepend(`<b>${title}</b>`).addClass("chat-message")
  167. );
  168. break;
  169. }
  170. }
  171. }
  172. }
  173.  
  174. this.colorKillWord = function (obj) {
  175. const str = $(obj).html();
  176. const newStr = str.replace(/Zabij:/gi, '<span class="red">Zabij:</span>');
  177.  
  178. $(obj).html(newStr);
  179. };
  180.  
  181. const chat = $(".left-column .messages-wrapper .scroll-pane");
  182. let inited = false;
  183.  
  184. this.watchChatChanges = () => {
  185. const observer = new MutationObserver(() => {
  186. if(!chat.find(".pinned-quests").length) {
  187. if(!inited) {
  188. inited = true;
  189. this.refreshQuests();
  190. }
  191. chat.append(chatQuests);
  192. }
  193. });
  194. observer.observe(chat.get(0), {childList: true});
  195. }
  196.  
  197. this.detectEndBattle = () => {
  198. const _detectEndBattle = Engine.communication.dispatcher.on_f;
  199.  
  200. Engine.communication.dispatcher.on_f = (data) => {
  201. if (data.close !== undefined && data.close == 1) {
  202. this.refreshQuests();
  203. }
  204. return _detectEndBattle.apply(this, [data]);
  205. }
  206. }
  207.  
  208. this.detectNewDialogues = () => {
  209. const _detectDialogues = Engine.communication.dispatcher.on_d;
  210.  
  211. Engine.communication.dispatcher.on_d = (data, all_data) => {
  212. if(!(data[0] == 4 && all_data.f !== undefined)) {
  213. this.refreshQuests();
  214. }
  215. return _detectDialogues.apply(this, [data]);
  216. }
  217. }
  218.  
  219. this.init = () => {
  220. pinnedQuests = API.Storage.get(lsName) || {};
  221.  
  222. this.detectQuestsWindowInit();
  223. this.watchChatChanges();
  224. this.detectEndBattle();
  225. this.detectNewDialogues();
  226. }
  227.  
  228. this.init();
  229. })(window.Engine, window.API, window.$);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top