Skip to content

Commit 183e108

Browse files
committed
Show message after blocking
1 parent df62427 commit 183e108

1 file changed

Lines changed: 57 additions & 27 deletions

File tree

src/scripts/inject.js

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,46 +1514,85 @@
15141514
return { ...result, attr };
15151515
}
15161516

1517-
function injectBlockMenuItems(items, hasChannel, hasVideo, isLockupViewModel, storageData) {
1517+
function injectBlockMenuItems(items, hasChannel, hasVideo, isLockupViewModel, currentObj, storageData) {
15181518
if (isLockupViewModel) {
1519-
return injectLockupViewModelButtons(items, hasChannel, hasVideo, storageData);
1519+
return injectLockupViewModelButtons(items, hasChannel, hasVideo, currentObj, storageData);
15201520
} else {
15211521
return injectStandardMenuButtons(items, hasChannel, hasVideo, storageData);
15221522
}
15231523
}
15241524

1525-
function injectLockupViewModelButtons(items, hasChannel, hasVideo, storageData) {
1525+
function injectLockupViewModelButtons(items, hasChannel, hasVideo, currentObj, storageData) {
15261526
if (!items.length) return;
15271527

1528-
const { removeItem: removeItemChannel, baseContext: cleanChannelContext } = createCleanContext(items, storageData, true);
1529-
const { removeItem: removeItemVideo, baseContext: cleanVideoContext } = createCleanContext(items, storageData, false);
1528+
const cleanChannelContext = createCleanContext(items, storageData, true, currentObj);
1529+
const cleanVideoContext = createCleanContext(items, storageData, false, currentObj);
15301530

15311531
const blockChannelItem = createLockupButtonItem('Block Channel', cleanChannelContext);
15321532
const blockVideoItem = createLockupButtonItem('Block Video', cleanVideoContext);
15331533

15341534
if (hasChannel) items.push(blockChannelItem);
15351535
if (hasVideo) items.push(blockVideoItem);
15361536

1537-
return removeItemChannel && removeItemVideo
1537+
return true;
15381538
}
15391539

1540-
function createCleanContext(items, storageData, isChannel) {
1540+
function createCleanContext(items, storageData, isChannel, currentObj) {
15411541
const item = isChannel ? items[6] : items[5];
15421542
if (storageData.options.block_feedback && item) {
1543-
const baseContext = item?.listItemViewModel?.rendererContext;
1544-
return {removeItem: false, baseContext};
1543+
return item?.listItemViewModel?.rendererContext;
15451544
}
15461545

15471546
const baseContext = items[0]?.listItemViewModel?.rendererContext;
15481547
if (!baseContext) return null;
1549-
1550-
const cleanContext = { ...baseContext };
1551-
// Prevent accidental execution
1552-
if (cleanContext.commandContext?.onTap?.innertubeCommand?.signalServiceEndpoint) {
1553-
cleanContext.commandContext.onTap.innertubeCommand.signalServiceEndpoint.actions = undefined;
1548+
1549+
const msg = isChannel ? 'Channel Blocked' : 'Video Blocked';
1550+
const cleanContext = deepClone(baseContext);
1551+
1552+
if (cleanContext.commandContext?.onTap) {
1553+
let onTap = cleanContext.commandContext?.onTap;
1554+
onTap.innertubeCommand = {
1555+
"clickTrackingParams": "",
1556+
"commandMetadata": {
1557+
"webCommandMetadata": {
1558+
"sendPost": false,
1559+
"apiUrl": ""
1560+
}
1561+
},
1562+
"feedbackEndpoint": {
1563+
"feedbackToken": "",
1564+
"uiActions": {
1565+
"hideEnclosingContainer": true
1566+
},
1567+
"actions": [
1568+
{
1569+
"clickTrackingParams": "",
1570+
"replaceEnclosingAction": {
1571+
"item": {
1572+
"notificationMultiActionRenderer": {
1573+
"responseText": {
1574+
"accessibility": {
1575+
"accessibilityData": {
1576+
"label": msg
1577+
}
1578+
},
1579+
"simpleText": msg
1580+
},
1581+
"buttons": [
1582+
],
1583+
"trackingParams": "",
1584+
"dismissalViewStyle": "DISMISSAL_VIEW_STYLE_COMPACT_TALL"
1585+
}
1586+
}
1587+
}
1588+
}
1589+
],
1590+
"contentId": currentObj.contentId
1591+
}
1592+
}
15541593
}
15551594

1556-
return {removeItem: true, baseContext: cleanContext};
1595+
return cleanContext;
15571596
}
15581597

15591598
function createLockupButtonItem(title, rendererContext) {
@@ -1614,19 +1653,12 @@
16141653

16151654
const { items, hasChannel, hasVideo, isLockupViewModel, attr } = extracted;
16161655

1617-
const removeItem = injectBlockMenuItems(items, hasChannel, hasVideo, isLockupViewModel, storageData);
1656+
injectBlockMenuItems(items, hasChannel, hasVideo, isLockupViewModel, obj[attr], storageData);
16181657

16191658
// Attach metadata only if needed
16201659
if (hasChannel || hasVideo) {
16211660
obj[attr]._btOriginalAttr = attr;
16221661
}
1623-
1624-
if (isLockupViewModel && storageData.options.block_feedback && !removeItem) {
1625-
const path = 'metadata.lockupMetadataViewModel.menuButton.buttonViewModel.onTap.innertubeCommand.showSheetCommand.panelLoadingStrategy.inlineContent.sheetViewModel';
1626-
const sheetmodel = getObjectByPath(obj[attr], path);
1627-
if (sheetmodel?.blockTube?.metadata)
1628-
sheetmodel.blockTube.metadata.removeObject = false; // Removing handled by yt
1629-
}
16301662
}
16311663

16321664
function startHook() {
@@ -1864,7 +1896,7 @@
18641896
text: parentData.blockTube?.metadata?.videoName,
18651897
};
18661898

1867-
removeParent = parentData.blockTube?.metadata?.removeObject
1899+
removeParent = false
18681900
stopPlayer = false
18691901
} else {
18701902
const attrKey = parentData._btOriginalAttr;
@@ -1939,7 +1971,7 @@
19391971
return {};
19401972
}
19411973

1942-
parentDom = eventSink.parentComponent || eventSink.parentElement.__dataHost.hostElement;
1974+
parentDom = eventSink.parentComponent || eventSink.parentElement.__dataHost?.hostElement || eventSink.parentElement?.parentElement;
19431975
parentData = parentDom?.data;
19441976

19451977
if (!parentDom || !parentData) {
@@ -1962,8 +1994,6 @@
19621994
} else {
19631995
parentDom.remove();
19641996
}
1965-
} else if (isDataFromRightHandSide) {
1966-
parentDom.parentNode.__dataHost.__restoreFocusNode.parentElement.parentElement.parentElement.parentElement.parentElement.remove()
19671997
} else {
19681998
parentDom.dismissedRenderer = {
19691999
notificationMultiActionRenderer: {

0 commit comments

Comments
 (0)