Skip to content

Commit

Permalink
Merge pull request #240 from makyen/Mak-FIRE-remove-DOMSubtreeModified
Browse files Browse the repository at this point in the history
FIRE 1.6.2: remove DOMSubtreeModified
  • Loading branch information
makyen authored Jul 28, 2024
2 parents 4da0adb + 975fa5d commit 3aebc2c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
1 change: 1 addition & 0 deletions fire/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ installed. In order to fully reset, you would need to run this in the browser co

|1.6 ||
| --- |---
|1.6.2 |Remove use of `DOMSubtreeModified` event , as it will be removed from Chrome shortly.
|1.6.1 |Adapt to SE supplying unexpected data when using the implicit OAuth 2.0 flow.
|1.6.0 |Copying to chat input upon <kbd>Alt</kbd>-<kbd>Click</kbd>. See above for a more detailed description.

Expand Down
2 changes: 1 addition & 1 deletion fire/fire.meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// @description FIRE adds a button to SmokeDetector reports that allows you to provide feedback & flag, all from chat.
// @author Cerbrus [attribution: Michiel Dommerholt (https://github.com/Cerbrus)]
// @contributor Makyen
// @version 1.6.1
// @version 1.6.2
// @icon https://raw.githubusercontent.com/Ranks/emojione-assets/master/png/32/1f525.png
// @updateURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/fire/fire.meta.js
// @downloadURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/fire/fire.user.js
Expand Down
52 changes: 28 additions & 24 deletions fire/fire.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// @description FIRE adds a button to SmokeDetector reports that allows you to provide feedback & flag, all from chat.
// @author Cerbrus [attribution: Michiel Dommerholt (https://github.com/Cerbrus)]
// @contributor Makyen
// @version 1.6.1
// @version 1.6.2
// @icon https://raw.githubusercontent.com/Ranks/emojione-assets/master/png/32/1f525.png
// @updateURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/fire/fire.meta.js
// @downloadURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/fire/fire.user.js
Expand Down Expand Up @@ -4741,9 +4741,17 @@ body.outside .fire-popup h2 {
*
*/
function showFireOnExistingMessages() {
$('#getmore, #getmore-mine')
.click(() => decorateExistingMessages(fire.constants.loadAllMessagesDelay));
$(document).ajaxComplete((event, jqXHR, ajaxSettings) => {
if (/^\/chats\/\d+\/events/i.test(ajaxSettings.url)) {
// By the time this gets called, the messages are in the DOM.
// The URL for getting message events is /chats/<room #>/events.
// This works in chat rooms for both the intial load of messages and
// getting additional messages.
decorateExistingMessages(0);
}
});

// This is needed in any other chat pages, other than actual chat rooms.
decorateExistingMessages(0);

// Load report data on fire button hover
Expand All @@ -4753,7 +4761,7 @@ body.outside .fire-popup h2 {
}

/**
* decorateExistingMessages - Decorate messages that exist on page load.
* decorateExistingMessages - Decorate any appropriate messages in the page which are not already decorated.
*
* @private
* @memberof module:fire
Expand All @@ -4763,26 +4771,22 @@ body.outside .fire-popup h2 {
function decorateExistingMessages(timeout) {
const chat = $(/^\/(?:search|users)/.test(window.location.pathname) ? '#content' : '#chat,#transcript');

chat.one('DOMSubtreeModified', () => {
// We need another timeout here, because the first modification occurs before
// the new (old) chat messages are loaded.
setTimeout(() => {
if (chat.html().length === 0) { // Too soon
setTimeout(decorateExistingMessages, timeout, timeout);
} else { // Chat messages have loaded
$(fire.SDMessageSelector).each((i, element) => decorateMessage(element));

fire.log('Decorated existing messages.');

/* eslint-disable no-warning-comments */
/*
TODO: Load Stack Exchange data for each report
updateReportCache();
*/
/* eslint-enable no-warning-comments */
}
}, timeout);
});
setTimeout(() => {
if (chat.html().length === 0) { // Too soon
setTimeout(decorateExistingMessages, timeout || fire.constants.millisecondsInSecond, timeout);
} else { // Chat messages have loaded
$(fire.SDMessageSelector).each((i, element) => decorateMessage(element));

fire.log('Decorated existing messages.');

/* eslint-disable no-warning-comments */
/*
TODO: Load Stack Exchange data for each report
updateReportCache();
*/
/* eslint-enable no-warning-comments */
}
}, timeout);
$(fire.SDMessageSelector).each((i, element) => decorateMessage(element));
}

Expand Down

0 comments on commit 3aebc2c

Please sign in to comment.