Skip to content

Instantly share code, notes, and snippets.

@ttycelery
Last active June 3, 2022 15:10
Show Gist options
  • Save ttycelery/a484efb79ad6ba1496de59fbb1b26568 to your computer and use it in GitHub Desktop.
Save ttycelery/a484efb79ad6ba1496de59fbb1b26568 to your computer and use it in GitHub Desktop.
DarkenLINE: a dark mode css hack for LINE (Chrome extension version)

DarkenLINE

A simple Python script designed to invert the color scheme of the LINE app (Chrome extension version). It basically does the following things:

  • Read the contents of the current line_chrome.min.css
  • Invert all colors contained in rgba(..., ..., ...) and #...... (only invert if luminosity > 40)
  • Add an additional CSS at the top
  • Print the output to stdout

Finally, you can change your current line_chrome.min.css with the output.

import sys
import re
import sys
import re
from PIL import ImageColor
extra_css = """\
* {
color: rgba(255, 255, 255, .6) !important;
}
div[class$="Own"] > * div[class$="MsgText"] {
filter: grayscale(1) !important;
// background-color: #151515 !important;
}
div[class*="Badge"] {
background-color: #181818 !important;
}
#_chat_detail_area {
border-color: #121212 !important;
}
#_chat_sticker_tab, #_sticker_tab_area, #_sticker_list_area {
background-color: #000000 !important;
}
body, input, input[type=password] {
font-family: "Noto Sans", sans-serif !important;
background-color: black !important;
color: rgba(255, 255, 255, .6) !important;
}
"""
def luma(r, g, b):
return 0.2126 * r + 0.7152 * g + 0.0722 * b
def main(filename):
with open(filename) as f:
content = f.read()
colors = set(re.findall(r'(#[a-z0-9]+)', content, re.M))
for color in colors:
try:
r, g, b = ImageColor.getrgb(color)
except ValueError:
continue
r, g, b = (255-r), (255-g), (255-b)
if luma(r, g, b) < 50:
new_color = f'#{r:02x}{g:02x}{b:02x}'
content = content.replace(color, new_color)
def sub_rgba(match):
r, g, b, a = (match.group(i+1) for i in range(4))
r, g, b, a = int(r), int(g), int(b), float(a)
res = match.group(0)
if luma(r, g, b) > 40:
r, g, b = (255-r), (255-g), (255-b)
for i, v in enumerate((r, g, b)):
res = res.replace(match.group(i + 1), str(v))
return res
content = re.sub(r'rgba\((\d+),\s?(\d+),\s?(\d+),\s?([\.0-9]+)\)',
sub_rgba, content, flags=re.M)
content = content.replace('url(../img/sprite/common.png)',
'url(../img/sprite/common.png);\nfilter: grayscale(1) invert(1);')
print(extra_css)
print(content)
if __name__ == '__main__':
if len(sys.argv) != 2:
print(
f'usage: {sys.argv[0]} <path_to_line_chrome.min.css>', file=sys.stderr)
sys.exit(-1)
main(sys.argv[1])
from PIL import ImageColor
extra_css = """\
* {
color: rgba(255, 255, 255, .6) !important;
}
#_chat_detail_area {
border-color: #121212 !important;
}
#_sticker_tab_area, #_sticker_list_area {
background-color: #000000 !important;
}
body, input, input[type=password] {
font-family: "Noto Sans", sans-serif !important;
background-color: black !important;
color: rgba(255, 255, 255, .6) !important;
}
"""
def luma(r, g, b):
return 0.2126 * r + 0.7152 * g + 0.0722 * b
def main(filename):
with open(filename) as f:
content = f.read()
colors = set(re.findall(r'(#[a-z0-9]+)', content, re.M))
for color in colors:
try:
r, g, b = ImageColor.getrgb(color)
except ValueError:
continue
r, g, b = (255-r), (255-g), (255-b)
if luma(r, g, b) < 50:
new_color = f'#{r:02x}{g:02x}{b:02x}'
content = content.replace(color, new_color)
def sub_rgba(match):
r, g, b, a = (match.group(i+1) for i in range(4))
r, g, b, a = int(r), int(g), int(b), float(a)
res = match.group(0)
if luma(r, g, b) > 40:
r, g, b = (255-r), (255-g), (255-b)
for i, v in enumerate((r, g, b)):
res = res.replace(match.group(i + 1), str(v))
return res
content = re.sub(r'rgba\((\d+),\s?(\d+),\s?(\d+),\s?([\.0-9]+)\)',
sub_rgba, content, flags=re.M)
content = content.replace('url(../img/sprite/common.png)',
'url(../img/sprite/common.png);\nfilter: invert(1);')
print(extra_css)
print(content)
if __name__ == '__main__':
if len(sys.argv) != 2:
print(f'usage: {sys.argv[0]} <path_to_line_chrome.min.css>', file=sys.stderr)
sys.exit(-1)
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment