Created
August 14, 2020 14:21
-
-
Save mwgamera/fcabf488b538613948f815f0a6255353 to your computer and use it in GitHub Desktop.
I tried using qutebrowser lately
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# klg, Aug 2020 | |
# frozen_string_literal: true | |
files = {} | |
Dir[File.join(Dir.home, '.{js,css}/?*.{js,css}')].each do |ent| | |
sta = File.stat(ent) # not lstat | |
files[[sta.dev, sta.ino]] ||= [] | |
files[[sta.dev, sta.ino]] << ent | |
end | |
files.values.each do |paths| | |
domains = paths.map { |x| x[%r{/([^/]+)\.(js|css)$}, 1] } | |
domains.sort! | |
type = paths[0][/\.([^.]+)$/, 1] | |
out = "./dotjs-#{type}-#{domains[0]}.js" | |
warn paths | |
warn '-> ' + out | |
File.open(out, 'w') do |f| | |
f.write("// AUTOMATICALLY GENERATED FROM <#{paths[0]}>\n") | |
f.write("// ==UserScript==\n") | |
domains.each do |host| | |
if host == 'default' | |
f.write("// @include *\n") | |
else | |
f.write("// @match *://*.#{host}/*\n") | |
end | |
end | |
f.write("// @run-at document-end\n") | |
f.write("// ==/UserScript==\n\n") | |
case type | |
when 'js' | |
IO.copy_stream(paths[0], f) | |
when 'css' | |
css = File.read(paths[0]) | |
css = css.gsub(/[\\$`]/) { |x| '\\' + x } | |
css.chomp! | |
f.write("document.head.appendChild(document.createElement('style')).innerText = `\n#{css}\n`\n") | |
else | |
raise | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment