Skip to content

Commit e2d48e5

Browse files
Various improvements
1 parent 1645e85 commit e2d48e5

20 files changed

+266
-220
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,19 @@ Finally, install the userscript from OpenUserJS :
7474

7575
I recommend using [Violentmonkey](https://violentmonkey.github.io/) or similar and enable userscript autoreloading as explained in here https://violentmonkey.github.io/posts/how-to-edit-scripts-with-your-favorite-editor/
7676

77-
Install all dependencies:
77+
Install dependencies:
7878
- ``npm install``
7979

80-
Start rollup with the watch flag:
80+
To both serve and build with autoreloading:
8181
- ``npm start``
8282

83+
> This will also start an HTTP server and allow autoreloading of the userscript as changes are made.
84+
8385
You can also do a one-time build with:
8486
- ``npm run build``
8587

88+
> The script will build to ``dist/idmu.user.js`` by default.
89+
8690
## This might not work
8791

8892
Instagram web app is serving different UIs probably based on the user location. [Yours might not be supported](https://github.com/thoughtsunificator/instagram-dm-unsender/issues/1)

package-lock.json

Lines changed: 55 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"eslint": "^8.43.0",
2323
"husky": "^8.0.3",
2424
"jsdom": "^22.1.0",
25-
"rollup": "^3.25.3"
25+
"rollup": "^3.25.3",
26+
"rollup-plugin-serve": "^1.1.1"
2627
}
2728
}

rollup.userscript.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
import fs from "fs"
44
import nodeResolve from "@rollup/plugin-node-resolve"
5+
import serve from "rollup-plugin-serve"
56
import pkg from "./package.json" assert { type: "json" }
67

8+
const isProduction = process.env.BUILD === "production"
9+
const isDevelopment = !isProduction
10+
711
export default {
812
input: "./src/runtime/userscript/main.js",
913
output: {
@@ -28,5 +32,9 @@ export default {
2832
}
2933
},
3034
nodeResolve(),
35+
isDevelopment && serve({
36+
contentBase: "dist",
37+
port: process.env.PORT || 3000
38+
}),
3139
]
3240
}

src/dom/async-events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function waitForElement(target, getElement, controller=new AbortControlle
2020
return new Promise((resolve, reject) => {
2121
let mutationObserver
2222
const abortHandler = () => {
23-
console.log("abortController")
23+
console.debug("abortController")
2424
reject(new DOMException("Aborted", "AbortError"))
2525
if(mutationObserver) {
2626
mutationObserver.disconnect()

src/idmu/idmu.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ class IDMU {
1010
/**
1111
*
1212
* @param {Window} window
13+
* @param {callback} onStatusText
1314
*/
14-
constructor(window) {
15+
constructor(window, onStatusText) {
1516
this.window = window
1617
this.uipi = null
18+
this.onStatusText = onStatusText
1719
}
1820

1921
/**
@@ -24,6 +26,14 @@ class IDMU {
2426
return this.#getUIPI().createUIPIMessages()
2527
}
2628

29+
/**
30+
*
31+
* @param {string} text
32+
*/
33+
setStatusText(text) {
34+
this.onStatusText(text)
35+
}
36+
2737

2838
/**
2939
*
@@ -39,10 +49,11 @@ class IDMU {
3949
*/
4050
#getUIPI() {
4151
if(this.uipi === null) {
42-
this.uipi = UIPI.create(this.window, this.UI)
52+
this.uipi = UIPI.create(this.window)
4353
}
4454
return this.uipi
4555
}
4656

57+
4758
}
4859
export default IDMU

src/idmu/idmu.test.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test("IDMU", t => {
1414
test("IDMU fetchAndRenderThreadNextMessagePage", async t => {
1515
t.context.mountElement.append(createMessagesWrapperElement(t.context.document))
1616
const messagesWrapperElement = findMessagesWrapper(t.context.window)
17-
const idmu = new IDMU(t.context.window)
17+
const idmu = new IDMU(t.context.window, () => {})
1818
messagesWrapperElement.innerHTML += `<div role="progressbar"></div>`
1919
const result = idmu.fetchAndRenderThreadNextMessagePage()
2020
messagesWrapperElement.querySelector("[role=progressbar]").remove()
@@ -25,9 +25,20 @@ test("IDMU createUIPIMessages", async t => {
2525
const messagesWrapperElement = createMessagesWrapperElement(t.context.document)
2626
t.context.mountElement.append(messagesWrapperElement)
2727
const messageElement = createMessageElement(t.context.document, "cxzc423Testsdfdsfsdfsdfds")
28-
const idmu = new IDMU(t.context.window)
28+
const idmu = new IDMU(t.context.window, () => {})
2929
findMessagesWrapper(t.context.window).appendChild(messageElement)
3030
const uipiMessages = await idmu.createUIPIMessages()
3131
t.is(uipiMessages.length, 1)
3232
t.is(uipiMessages[0].uiMessage.root.querySelector("span").textContent, "cxzc423Testsdfdsfsdfsdfds")
3333
})
34+
35+
36+
test("IDMU onStatusText", t => {
37+
let text = ""
38+
const callback = () => {
39+
text = "text"
40+
}
41+
const idmu = new IDMU(t.context.window, callback)
42+
idmu.onStatusText("text")
43+
t.is(text, "text")
44+
})

src/runtime/userscript/ui/menu.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
*/
77
export function createMenuElement(document) {
88
const menuElement = document.createElement("div")
9+
menuElement.id = "idmu-menu"
910
menuElement.style.top = "20px"
1011
menuElement.style.right = "430px"
1112
menuElement.style.position = "fixed"
1213
menuElement.style.zIndex = 999
1314
menuElement.style.display = "flex"
1415
menuElement.style.gap = "10px"
16+
menuElement.style.placeItems = "center"
1517
return menuElement
1618
}

0 commit comments

Comments
 (0)