Removed XSS in infoblock creation, moved infoblock creation into a separate file, formatted atlas.json and made it distinct by description if it's longer than 10 characters

This commit is contained in:
asivery 2022-04-05 12:32:59 +02:00
parent 4bfd98f1be
commit cc88efcf36
5 changed files with 1185 additions and 58 deletions

48
web/_js/infoblock.js Normal file
View file

@ -0,0 +1,48 @@
function createInfoBlock(entry) {
var element = document.createElement("div");
element.className = "object";
let headerElement = document.createElement("h2");
let linkElement = document.createElement("a");
linkElement.href = "?" + entry.id;
linkElement.innerText = entry.name;
headerElement.appendChild(linkElement);
element.appendChild(headerElement);
if (entry.description) {
let descElement = document.createElement("p");
descElement.innerText = entry.description;
element.appendChild(descElement);
}
if (entry.website) {
let websiteLinkElement = document.createElement("a");
websiteLinkElement.target = "_blank";
websiteLinkElement.href = entry.website;
websiteLinkElement.innerText = "Website";
element.appendChild(websiteLinkElement);
}
if (entry.subreddit) {
var subreddits = entry.subreddit.split(",");
for (var i in subreddits) {
var subreddit = subreddits[i].trim();
if (subreddit.substring(0, 2) == "r/") {
subreddit = "/" + subreddit;
} else if (subreddit.substring(0, 1) != "/") {
subreddit = "/r/" + subreddit;
}
let subredditLinkElement = document.createElement("a");
subredditLinkElement.target = "_blank";
subredditLinkElement.href = "https://reddit.com" + subreddit;
subredditLinkElement.innerText = subreddit;
element.appendChild(subredditLinkElement);
}
}
let idElement = document.createElement("p");
idElement.style.fontFamily = "Dejavu Sans Mono, sans, Sans-Serif;";
idElement.innerText = "id: " + entry.id;
element.appendChild(idElement);
return element;
}

View file

@ -131,32 +131,6 @@ function initOverlap(){
updateLines();
});
function createInfoBlock(entry){
var element = document.createElement("div");
element.className = "object";
var html = '<h2><a href="?id='+entry.id+'">'+entry.name+'</a></h2>';
if(entry.description){
html += '<p>'+entry.description+'</p>';
}
if(entry.website){
html += '<a target="_blank" href='+entry.website+'>Website</a>';
}
if(entry.subreddit){
if(entry.subreddit.substring(0, 2) == "r/"){
entry.subreddit = "/" + entry.subreddit;
} else if(entry.subreddit.substring(0, 1) != "/"){
entry.subreddit = "/r/" + entry.subreddit;
}
html += '<a target="_blank" href=https://reddit.com'+entry.subreddit+'>'+entry.subreddit+'</a>';
}
html+="<p style='font-family: Dejavu Sans Mono, sans, Sans-Serif;'>id: "+entry.id+"</p>";
element.innerHTML += html;
return element;
}
function highlightEntryFromUrl(){
var objectsContainer = document.getElementById("objectsList");

View file

@ -257,37 +257,6 @@ function initView(){
}
}
function createInfoBlock(entry){
var element = document.createElement("div");
element.className = "object";
var html = "<h2><a href=\"?id="+entry.id+"\">"+entry.name+"</a></h2>";
if(entry.description){
html += "<p>"+entry.description+"</p>";
}
if(entry.website){
html += "<a target=\"_blank\" href="+entry.website+">Website</a>";
}
if(entry.subreddit){
var subreddits = entry.subreddit.split(",");
for(var i in subreddits){
var subreddit = subreddits[i].trim();
if(subreddit.substring(0, 2) == "r/"){
subreddit = "/" + subreddit;
} else if(subreddit.substring(0, 1) != "/"){
subreddit = "/r/" + subreddit;
}
html += "<a target=\"_blank\" href=https://reddit.com"+subreddit+">"+subreddit+"</a>";
}
}
html+="<p style='font-family: Dejavu Sans Mono, sans, Sans-Serif;'>id: "+entry.id+"</p>";
element.innerHTML += html;
return element;
}
function highlightEntryFromUrl(){
var objectsContainer = document.getElementById("objectsList");

File diff suppressed because one or more lines are too long

View file

@ -229,6 +229,7 @@ <h2>His Bitcoin Address</h2>
Code by <a href="https://draemm.li/various/place-atlas/" target="_blank" rel="author">Roland Rytz</a>. Source on <a target="_blank" href="https://github.com/RolandR/place-atlas">GitHub</a> (<a target="_blank" href="https://github.com/Codixer/place-atlas">2022 Version Github</a>). Images provided by <a target="_blank" href="https://place.thatguyalex.com/">Alex Tsernoh</a>.
</div>
</div>
<script type="text/javascript" src="./_js/infoblock.js?version=1.0"></script>
<script type="text/javascript" src="./_js/pointInPolygon.js?version=1.0"></script>
<script type="text/javascript" src="./_js/atlas.js?version=1.0.50"></script>
<script type="text/javascript" src="./_js/view.js?version=1.0.4"></script>