Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bramses committed Jun 2, 2022
1 parent cea62bb commit 4f2a556
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ import { EditorExtensions } from "editor-enhancements";
export default class StackOverflowAnswers extends Plugin {

extractAnswerId(url: string) {
if (url.includes("#"))
// in form of https://stackoverflow.com/questions/14122919/how-to-hide-show-objects-using-three-js-release-54/14123978#14123978
return url.split("#").pop();

const urlPopped = url.split("/"); // in form of https://stackoverflow.com/a/32232028/3952024
urlPopped.pop();
return urlPopped.pop(); // second to last
try {
if (url.length === 0) {
new Notice("[Stack Overflow Answers] - url is empty");
return "";
}
if (url.includes("#"))
// in form of https://stackoverflow.com/questions/14122919/how-to-hide-show-objects-using-three-js-release-54/14123978#14123978
return url.split("#").pop();

const urlPopped = url.split("/"); // in form of https://stackoverflow.com/a/32232028/3952024
urlPopped.pop();
return urlPopped.pop(); // second to last
} catch (err) {
new Notice("[Stack Overflow Answers] - Could not extract answer id from url");
return "";
}
}

extractParagraphs(html: HTMLElement) {
Expand Down Expand Up @@ -98,12 +107,12 @@ export default class StackOverflowAnswers extends Plugin {
async conveyorBelt(url = "") {
if (url.length === 0) {
new Notice("[Stack Overflow Answers] - Nothing Selected");
return;
return "";
}

if (!url.includes("stackoverflow.com")) {
new Notice("[Stack Overflow Answers] - Invalid URL");
return;
return "";
}

const res = await request({
Expand Down Expand Up @@ -187,12 +196,6 @@ export default class StackOverflowAnswers extends Plugin {
const selectedText = (EditorExtensions.getSelectedText(editor) || "").trim();
this.convertUrlToTitledLink(editor, selectedText);
},
hotkeys: [
{
modifiers: ["Mod", "Shift"],
key: "v",
},
],
});
}

Expand Down

0 comments on commit 4f2a556

Please sign in to comment.