Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.1 #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

5.1 #44

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 48 additions & 26 deletions better-osm-org.user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Better osm.org
// @version 0.5
// @version 0.5.1
// @description Several improvements for advanced users of osm.org
// @author deevroman
// @match https://www.openstreetmap.org/*
Expand Down Expand Up @@ -43,6 +43,7 @@
// @connect resultmaps.neis-one.org
// @connect www.openstreetmap.org
// @connect osmcha.org
// @connect overpass-api.de
// @sandbox JavaScript
// @resource OAUTH_HTML https://github.com/deevroman/better-osm-org/raw/master/finish-oauth.html
// @resource OSMCHA_ICON https://github.com/deevroman/better-osm-org/raw/master/icons/osmcha.ico
Expand Down Expand Up @@ -376,11 +377,12 @@ function addRevertButton() {
const changeset_id = sidebar.innerHTML.match(/(\d+)/)[0];

async function uncheck(changeset_id) {
return await fetch(`https://osmcha.org/api/v1/changesets/${changeset_id}/uncheck/`, {
"headers": {
return await GM.xmlHttpRequest({
url: `https://osmcha.org/api/v1/changesets/${changeset_id}/uncheck/`,
headers: {
"Authorization": "Token " + GM_getValue("OSMCHA_TOKEN"),
},
"method": "PUT",
method: "PUT",
});
}

Expand Down Expand Up @@ -411,11 +413,12 @@ function addRevertButton() {
await uncheck(changeset_id)
await updateReactions()
}
await fetch(`https://osmcha.org/api/v1/changesets/${changeset_id}/set-good/`, {
"headers": {
await GM.xmlHttpRequest({
url: `https://osmcha.org/api/v1/changesets/${changeset_id}/set-good/`,
headers: {
"Authorization": "Token " + GM_getValue("OSMCHA_TOKEN"),
},
"method": "PUT",
method: "PUT",
});
await updateReactions()
}
Expand Down Expand Up @@ -447,27 +450,30 @@ function addRevertButton() {
await uncheck(changeset_id)
await updateReactions()
}
await fetch(`https://osmcha.org/api/v1/changesets/${changeset_id}/set-harmful/`, {
"headers": {
await GM.xmlHttpRequest({
url: `https://osmcha.org/api/v1/changesets/${changeset_id}/set-harmful/`,
headers: {
"Authorization": "Token " + GM_getValue("OSMCHA_TOKEN"),
},
"method": "PUT",
method: "PUT",
});
await updateReactions()
}

async function updateReactions() {
const res = await fetch("https://osmcha.org/api/v1/changesets/" + changeset_id, {
"headers": {
const res = await GM.xmlHttpRequest({
url: "https://osmcha.org/api/v1/changesets/" + changeset_id,
method: "GET",
headers: {
"Authorization": "Token " + GM_getValue("OSMCHA_TOKEN"),
},
"method": "GET",
});
responseType: "json"
})
if (res.status === 404) {
console.warn("Changeset not found in OSMCha database")
return;
}
const json = await res.json();
const json = res.response;
if (json['properties']['check_user']) {
document.querySelector(".check_user")?.remove()
likeImg.style.filter = "grayscale(1)"
Expand Down Expand Up @@ -2035,15 +2041,30 @@ async function loadRelationVersionMembersViaOverpass(id, timestamp, cleanPrevObj
if (overpassCache[[id, timestamp]]) {
return overpassCache[[id, timestamp]]
} else {
const res = await fetch("https://overpass-api.de/api/interpreter?" + new URLSearchParams({
data: `
[out:json][date:"${timestamp}"];
relation(${id});
//(._;>;);
out geom;
`
}), {signal: abortDownloadingController.signal})
return overpassCache[[id, timestamp]] = await res.json()
try {
const res = await fetch("https://overpass-api.de/api/interpreter?" + new URLSearchParams({
data: `
[out:json][date:"${timestamp}"];
relation(${id});
//(._;>;);
out geom;
`
}), {signal: abortDownloadingController.signal})
return overpassCache[[id, timestamp]] = await res.json()
} catch (e) {
const res = await GM.xmlHttpRequest({
url: "https://overpass-api.de/api/interpreter?" + new URLSearchParams({
data: `
[out:json][date:"${timestamp}"];
relation(${id});
//(._;>;);
out geom;
`
}),
responseType: "json"
});
return overpassCache[[id, timestamp]] = res.response
}
}
}

Expand Down Expand Up @@ -2187,7 +2208,6 @@ function setupRelationVersionView() {
return [lat, lon]
})
displayWay(cloneInto(nodesList, unsafeWindow))

})
}
if (htmlElem.nodeName === "A") {
Expand Down Expand Up @@ -3208,6 +3228,7 @@ async function addChangesetQuickLook() {
icon.src = getIcon(left)
icon.style.height = "1em"
icon.style.marginLeft = "1px"
icon.style.marginTop = "-3px"
tagTd.appendChild(icon)
}
tagTd2.textContent = `${right?.ref ?? ""} ${right?.role ?? ""}`
Expand All @@ -3216,6 +3237,7 @@ async function addChangesetQuickLook() {
icon.src = getIcon(right)
icon.style.height = "1em"
icon.style.marginLeft = "1px"
icon.style.marginTop = "-3px"
tagTd2.appendChild(icon)
}
tagTd2.style.cursor = "";
Expand Down Expand Up @@ -3861,7 +3883,7 @@ async function addChangesetQuickLook() {
if (ways.length > 100 && changesetData.querySelectorAll("node") > 40) {
return;
}
if (ways.length > 500) {
if (ways.length > 520) {
return
}
}
Expand Down