Browse Source

Primary colors are handled by backend for better compatibility

tags/1.8.8
Leonie 3 months ago
parent
commit
d3ec2dbdc7
6 changed files with 76 additions and 21 deletions
  1. +5
    -0
      .gitignore
  2. +15
    -0
      backend.py
  3. +0
    -0
      files/.keep
  4. +2
    -1
      requirements.txt
  5. +28
    -16
      www/app.js
  6. +26
    -4
      www/style.css

+ 5
- 0
.gitignore View File

@@ -19,3 +19,8 @@ resources/signing
jsconfig.json
.vscode/
typings/

# backend downloads
files/*.png
files/*.jpg
files/*.gif

+ 15
- 0
backend.py View File

@@ -3,6 +3,7 @@

from bottle import get, post, request, response, route, run, redirect
from mastodon import Mastodon
from colorthief import ColorThief
import feedparser
import json
import os.path
@@ -251,4 +252,18 @@ def gefeatured_legacy():
l.append([i.split("#")[0], i.split("#")[1]])
return json.dumps(l)

@get("/api/v1/getprimarycolor")
def getprimarycolor():
response.headers['Access-Control-Allow-Origin'] = '*'
response.content_type = "text/plain"
url = request.query["url"] # pylint: disable=unsubscriptable-object
r = requests.get(url)
filename = "files/"+url.split("/")[len(url.split("/")) - 1]
with open(filename, 'wb') as f:
f.write(r.content)
color_thief = ColorThief(filename)
dominant_color = color_thief.get_color()
x = str(dominant_color).replace("(", "").replace(" ", "").replace(")", "")
return x

run(server="tornado",port=9000,host="0.0.0.0")

+ 0
- 0
files/.keep View File


+ 2
- 1
requirements.txt View File

@@ -2,4 +2,5 @@ bottle
tornado
feedparser
Mastodon.py
redis
redis
colorthief

+ 28
- 16
www/app.js View File

@@ -147,13 +147,11 @@ $(document).ready(function() {
$("#view__cast").show();
}
window.setTimeout(function() {
$("#img__cast").primaryColor({
callback: function(color) {
if (localStorage.getItem("darkmode") === "true") {
$("#podcard").attr("style", "background-image: linear-gradient(rgb("+color+"),#191919);");
} else {
$("#podcard").attr("style", "background-image: linear-gradient(rgb("+color+"),#fff);");
}
$.get(backend+"/api/v1/getprimarycolor?url="+callback.feed.image.href, function(color) {
if (localStorage.getItem("darkmode") === "true") {
$("#podcard").attr("style", "background-image: linear-gradient(rgb("+color+"),#191919);");
} else {
$("#podcard").attr("style", "background-image: linear-gradient(rgb("+color+"),#fff);");
}
});
$("#view__cast").show();
@@ -415,7 +413,25 @@ $(document).ready(function() {
podlist.split(",").forEach(function(feed) {
$.get(backend+"/api/v1/getpodcast?q="+feed, function(callback) {
try {
$("#section__list").html($("#section__list").html()+"<a class=\"cardlink\" data-cast=\""+Base64.encode(callback.href)+"\"><img src=\""+callback.feed.image.href+"\" class=\"card__small\" /></a>");
var secret = "";
try {
secret = callback.id.replaceAll("/", "-").replace(".", "-").replace(".", "-").replace(".", "-").replace(".", "-").replace(".", "-").replace(".", "-").replace("http:", "").replace("https:", "").replace("--", "").replace("+", "-").replaceAll(":", "-").replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"-").replace("?", "").replace("@", "");
} catch (e) {}
if (secret === "") {
secret = Base64.encode(feed).replaceAll("==", "");
}
var summary = "";
if (callback.feed.summary !== undefined) {
summary = callback.feed.summary;
}
$("#section__list").html($("#section__list").html()+"<div class=\"item\" id=\"itemcard-"+secret+"\"><div class=\"item-head\"><a class=\"cardlink\" data-cast=\""+Base64.encode(callback.href)+"\"><img src=\""+callback.feed.image.href+"\" class=\"card__small\" id=\"item-card-"+secret+"\" /></a><br><b>"+callback.feed.title+"</b></div><br><p>"+summary+"</p></div>");
$.get(backend+"/api/v1/getprimarycolor?url="+callback.feed.image.href, function(color) {
if (Number(color.split(",")[0]) > 128) {
$("#itemcard-"+secret).attr("style", "color:#333; background:rgb("+color+");");
} else {
$("#itemcard-"+secret).css('background-color', 'rgb('+color+')');
}
});
} catch (e) {}
});
});
@@ -462,15 +478,11 @@ $(document).ready(function() {
$.get(backend+"/api/v1/getfeatured/"+localStorage.getItem("lang"), function(data) {
data.forEach(function(item) {
$("#section__featured").html($("#section__featured").html()+"<div><a class=\"cardlink\" data-cast=\""+Base64.encode(item[1])+"\"><img src=\""+backend+"/api/v1/getbanner/"+item[0]+"\" class=\"card__big\" /></a></div>");
});
window.setTimeout(function() {
$(".card__big").primaryColor({
callback: function(color) {
$(this).css('box-shadow', '0px 0px 13px 2px rgba('+color+',0.75)');
}
$("#section__featured").html($("#section__featured").html()+"<div><a class=\"cardlink\" data-cast=\""+Base64.encode(item[1])+"\"><img src=\""+backend+"/api/v1/getbanner/"+item[0]+"\" class=\"card__big\" id=\"featured-"+Base64.encode(item[1]).replaceAll("=", "")+"\"/></a></div>");
$.get(backend+"/api/v1/getprimarycolor?url="+backend+"/api/v1/getbanner/"+item[0], function(color) {
$("#featured-"+Base64.encode(item[1]).replaceAll("=", "")).attr("box-shadow: 0px 0px 13px 2px rgba('+color+',0.75);");
});
},200);
});
if (data === "") {
$("#section__originals").hide();
$("#text__originals").hide();


+ 26
- 4
www/style.css View File

@@ -106,8 +106,8 @@ h1, h2, h3, h4, h5, h6 {
box-shadow: 0px 0px 3px -1px rgba(0,0,0,0.75);
border: 1px solid #ccc;
margin: 5px;
width: 80px;
height: 80px;
width: 100px;
height: 100px;
margin-bottom: 15px;
}

@@ -117,8 +117,8 @@ h1, h2, h3, h4, h5, h6 {
box-shadow: 0px 0px 3px -1px rgba(0,0,0,0.75);
border: 1px solid #f3f3f3;
margin: 5px;
width: 64px;
height: 64px;
width: 140px;
height: 140px;
margin-bottom: 15px;
}

@@ -378,6 +378,28 @@ h1 .emoji {
margin-bottom: 20px;
}

#section__list {
width: 90%;
margin: 0 auto;
display: block;
}

.item {
border: 3px solid #ccc;
margin-bottom: 20px;
border-radius: 4px;
width: 100%;
padding: 15px;
margin-left: -15px;
}

.item-head {
text-align: center;
padding-bottom: 10px;
margin: 0 auto;
width: 90%;
}

/* Hack for ionicicons v2 (no animation code) */
.ion-spin-animation { -webkit-animation: spin 1s infinite linear; -moz-animation: spin 1s infinite linear; -o-animation: spin 1s infinite linear; animation: spin 1s infinite linear; }



Loading…
Cancel
Save