Melvor Slayer Task Notification

Gives you a notification on Completion of Slayer Task

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Melvor Slayer Task Notification
// @namespace    http://tampermonkey.net/
// @version      0.2.0
// @description  Gives you a notification on Completion of Slayer Task
// @author       Breindahl#2660
// @match        https://*.melvoridle.com/*
// @grant        none
// ==/UserScript==
/* jshint esversion: 6 */

// Made for version 0.17

(function () {
	function injectScript(main) {
		var script = document.createElement('script');
		script.textContent = `try {(${main})();} catch (e) {console.log(e);}`;
		document.body.appendChild(script).parentNode.removeChild(script);
	}

	function script() {
		// Loading script
		console.log('Melvor Slayer Task Notification Loaded');

		function updateSlayerTaskOverwrite(qty) {
			if (qty > 0) {
				slayerTask[0].count -= qty;
				if (slayerTask[0].count < 1) {
					previousSlayerTask = slayerTask[0].monsterID;
					slayerTask = [];
					notifyPlayer(CONSTANTS.skill.Slayer, "You have completed your Slayer task.", "success");
					// Notification sound added
					let ding = new Audio("https://www.myinstants.com/media/sounds/ding-sound-effect.mp3");
					ding.volume=0.1;
					ding.play();
					// End of modification
					if (autoSlayerTask) getSlayerTask();
				}
			}
			if (!slayerTask.length) {
				$("#combat-player-slayer-task").html('<button type="button" class="btn btn-sm btn-success" onclick="getSlayerTask();">New Task</button>');
			} else {
				$('[data-toggle="tooltip"]').tooltip("hide");
				let a = findEnemyArea(slayerTask[0].monsterID);
				let cost = getSlayerCost();
				$("#combat-player-slayer-task").html(
					'<img class="skill-icon-xs m-0 mr-2 js-tooltip-enabled" src="' +
						MONSTERS[slayerTask[0].monsterID].media +
						'" data-toggle="tooltip" data-html="true" data-placement="bottom" title data-original-title="<small>Found in:</small><br><span class=\'text-warning\'>' +
						a +
						'</span>"><a class="combat-action" href="#" onClick="jumpToEnemy(' +
						slayerTask[0].monsterID +
						'); return false;">' +
						numberWithCommas(slayerTask[0].count) +
						" x " +
						MONSTERS[slayerTask[0].monsterID].name +
						"</a>"
				);
				$("#combat-player-slayer-new-btn").html('<a class="pointer-enabled combat-action" id="slayer-task-refresh" href="#" onclick="newSlayerTask(); return false;"><small>New Task</small></a>');
			}
		}

		window.updateSlayerTask = function(...args) {
			updateSlayerTaskOverwrite(...args);
		};
	}
	
	function loadScript() {
		if ((window.isLoaded && !window.currentlyCatchingUp) || (typeof unsafeWindow !== 'undefined' && unsafeWindow.isLoaded && !unsafeWindow.currentlyCatchingUp)) { // Only load script after game has opened
			clearInterval(scriptLoader);
			injectScript(script);
		}
	}

	const scriptLoader = setInterval(loadScript, 200);
})();