summaryrefslogtreecommitdiff
path: root/nomusic.lua
blob: 3b6d547fddd0f0919afd720c619d100af37d40da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
--[[ 

	file name: garrysmod/lua/menu/nomusic.lua
	reason: 
		to remove all that shitty music from shitty server's shitty loading screens they bought
		on scriptfucker™
	
	remember to add an include for this file in menu/menu.lua!
	
]]

--[[
	SETTINGS:
		alternate_iframe:
			used when shouldremove = false
			this will basically reroute the videos/sounds to the specified link
		shouldremove:
			if true it will simply remove the sounds/videos, otherwise it will use the other values in the settings
]]

local SETTINGS = {
	shouldremove = true;
	alternate_iframe = "https://www.youtube.com/embed/qycqF1CWcXg?autoplay=1";
};


local success	= Color(0,200,0,255);
local failure	= Color(200,0,0,255);
local middle	= Color(200,0,200,255); -- purple :)
local loadp = (GetLoadPanel or function() end)(); -- hopefully no change...
if(not loadp) then MsgC(failure, "Couldn't get pnlLoading! Not stopping sounds! :(\n"); end
MsgC(middle, "Got pnlLoading.. executing code to stop sounds...\n");

local ThinkName = "ThinkLoad";
local javascript = [[
	var amount = 0;
	function DeleteAll(name) {
		var all = document.getElementsByTagName(name);
		for(var i = 0; i < all.length; i++) {
			amount = amount + 1;
			all[i].parentElement.removeChild(all[i]);
		}
	}
	function KillSrc(name) {
	]]..(SETTINGS.shouldremove and [[
		DeleteAll(name);
	]] or [[
	var all = document.getElementsByTagName(name);
		for(var i = 0; i < all.length; i++) {
			amount = amount + 1;
			all[i].src = ']]..SETTINGS.alternate_iframe:JavascriptSafe()..[[';
		}
	]])..[[
	}
	KillSrc("iframe");
	DeleteAll("audio");
	KillSrc("source");
	console.log("Removed "+amount+" elements!");
]];
local overwrite = [[
	var old = document.createElement;
	document.createElement = function(tagname) {
		tagname = tagname.toLowerCase();
		if(tagname === "iframe" || tagname === "audio" || tagname === "source") {
			return; // sorry i am too lazy to redirect this to our stuff
		}
		return old(tagname);
	};
	console.log("Overwrote document.createElement :)!");
]];

local hasoverwritten = false;

local function ThinkLoad()
	if(not IsValid(loadp)) then hook.Remove("Think", ThinkName); return; end
	if(not IsValid(loadp.HTML)) then return; end -- wait for it
	if(hasoverwritten == false) then
		loadp.HTML:RunJavascript(overwrite);
		MsgC(success, "Overwrote document.createElement - ;)\n");
		hasoverwritten = true;
	end
	if(loadp.HTML:IsLoading()) then return; end -- wait for the load!
	loadp.HTML:RunJavascript(javascript);
	MsgC(success, "Removed all audio elements!\n");
	hook.Remove("Think", ThinkName); 
end

local old_showurl = loadp.ShowURL;
function loadp:ShowURL(a,b,c,d,e,f)
	MsgC(middle, "ShowURL called!\n");
	local ret = old_showurl(self,a,b,c,d,e,f);
	hasoverwritten = false;
	hook.Add("Think", ThinkName, ThinkLoad);
	return ret;
end
MsgC(success, "All code executed successfully!\n");

--scriptfucker and all other trademarks are property of their respective owners