Skip to content

Commit

Permalink
Add exclusion to menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenshin committed Apr 28, 2019
1 parent 163a9c6 commit 634c982
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ menu.OnClicked( ( info, tab ) => {
browser.tabs.create({ url: browser.extension.getURL( "options/options.html#later" ) });
} else if ( info.menuItemId == "whitelist" ) {
browser.tabs.sendMessage( tab.id, msg.Add( msg.MESSAGE_ACTION.menu_whitelist, {url: info.pageUrl } ));
} else if ( info.menuItemId == "exclusion" ) {
browser.tabs.sendMessage( tab.id, msg.Add( msg.MESSAGE_ACTION.menu_exclusion, {url: info.pageUrl } ));
} else {
if ( !tab.url.startsWith( "chrome://" ) ) browser.tabs.sendMessage( tab.id, msg.Add(info.menuItemId));
}
Expand Down
10 changes: 8 additions & 2 deletions src/contentscripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,15 @@ browser.runtime.onMessage.addListener( function( request, sender, sendResponse )
localStorage.removeItem( "sr-update-site" );
break;
case msg.MESSAGE_ACTION.menu_whitelist:
storage.read.whitelist.push( request.value.url );
storage.Write( () => {
case msg.MESSAGE_ACTION.menu_exclusion:
if ( request.type == msg.MESSAGE_ACTION.menu_whitelist ) {
storage.read.whitelist.push( request.value.url );
new Notify().Render( "已加入到白名单。" );
} else if ( request.type == msg.MESSAGE_ACTION.menu_exclusion ) {
storage.read.exclusion.push( request.value.url );
new Notify().Render( "已加入到排除列表。" );
}
storage.Write( () => {
watch.SendMessage( "option", true );
});
break;
Expand Down
4 changes: 4 additions & 0 deletions src/module/labs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export default class LabsOpt extends React.Component {
thumbedColor="#3F51B5" trackedColor="#7986CB" waves="md-waves-effect"
label="是否显示「加入白名单」?"
onChange={ (s)=>this.onChange(s, "option", "menu", "whitelist" ) } />
<Switch width="100%" checked={ this.props.option.menu.exclusion }
thumbedColor="#3F51B5" trackedColor="#7986CB" waves="md-waves-effect"
label="是否显示「加入到排除列表」?"
onChange={ (s)=>this.onChange(s, "option", "menu", "exclusion" ) } />
</div>

<div className="label">聚焦模式</div>
Expand Down
5 changes: 5 additions & 0 deletions src/service/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const context = {
link : { id: "", menu: {} },
list : { id: "", menu: {} },
whitelist : { id: "", menu: {} },
exclusion : { id: "", menu: {} },
},
menu = {
"type" : "normal",
Expand All @@ -25,6 +26,7 @@ Object.assign( context.read.menu, menu, { id: "read", "title" : "阅读模式"
Object.assign( context.list.menu, menu, { id: "list", "title" : "打开稍后读" });
Object.assign( context.link.menu, menu, { id: "link", "title" : "使用阅读模式打开此链接", contexts: [ "link" ] });
Object.assign( context.whitelist.menu, menu, { id: "whitelist", "title" : "将当前页面加入到白名单" });
Object.assign( context.exclusion.menu, menu, { id: "exclusion", "title" : "将当前页面加入到排除列表" });

/**
* Listen contextMenus message
Expand All @@ -51,6 +53,9 @@ function createAll() {

storage.option.menu.whitelist &&
( context.whitelist.id = browser.contextMenus.create( context.whitelist.menu ));

storage.option.menu.exclusion &&
( context.exclusion.id = browser.contextMenus.create( context.exclusion.menu ));
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/service/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const action = {
close_tab : "close_tab",
menu : "menu",
menu_whitelist : "menu_whitelist",
menu_exclusion : "menu_exclusion",
updated : "updated",
save_verify : "save_verify",
storage : "storage", // only firefox
Expand Down
1 change: 1 addition & 0 deletions src/service/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const name = "simpread",
link : true,
list : false,
whitelist: false,
exclusion: false,
},
origins : [],
blacklist : [
Expand Down

0 comments on commit 634c982

Please sign in to comment.