Skip to content

Commit

Permalink
Update inject-css.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
kozyakin committed Nov 19, 2024
1 parent 2b3c480 commit 0b9b1e3
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions html/inject-css.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
filecss = arg[1]
filehtml = arg[2]

local function readFile(filename)
local f = io.open(filename, "r")
if not f then return nil end
local content = f:read("*a")
f:close()
return content
local function readfile(name)
local f = assert(io.open(name, "r"))
local s = f:read("*a")
f:close()
return s
end

local function writeFile(file, data)
local f = io.open(file, "w")
if not f then return nil end
f:write(data)
f:close()
local function writefile(name, sum)
local f = assert(io.open(name, "w"))
f:write(sum)
f:close()
end

html = readFile(filehtml)
css = readFile(filecss)
html = readfile(filehtml)
css = readfile(filecss)
css = css:gsub('%%', '%%%%')

spattern = "<link .*href='" .. filecss .. "'.-/>"
Expand All @@ -27,7 +25,7 @@ injectedHtml = html:gsub(spattern, rpattern)
injectedHtml = injectedHtml:gsub('%%%%','%%')

if injectedHtml then
writeFile(filehtml, injectedHtml)
writefile(filehtml, injectedHtml)
print("\n\x1b[94mInject-CSS: done!\x1b[0m")
else
print("\n\x1b[91mInject-CSS: Sorry! Something went wrong!\x1b[0m")
Expand Down

0 comments on commit 0b9b1e3

Please sign in to comment.