Help us understand the problem. What is going on with this article?

doit.imのchrome拡張の仕様がいまいちなのをどうにかする

More than 5 years have passed since last update.

doit.imのchrome拡張でコンテクストメニューから
文字列を選択せずタスクを追加すると

タスク名:ページのURL
タスクノート:
という残念なタスクが登録されてしまう。

タスク名:ページのタイトル
タスクノート:ページのURL
となるようにしたい。

right_click.js.old
var title_page =  _L("background_add_page_url");
var id_page = chrome.contextMenus.create({
    'title': title_page, 'contexts':['page'], 'onclick': function(OnClickData){
        var tmp = $.trim(OnClickData.pageUrl);
        if(tmp.length > 225){
            alert(_L('TASK_VALI_TITLE_TOO_LONG'));
            return;
        }else{
            var task = {
                uuid:makeUUID(),
                title : tmp,
                notes : '',
                start_at : null,//要拼凑
                completed : null,
                all_day : true,
                attribute: 'inbox'
            }
            postTask(task,function(t){
                alert(_L('Success'));
            });
        }
        //alert('page '+OnClickData.pageUrl);
    }
});

onclickのコールバックの引数にtabを追加するだけで、
titleを取得することができます。

right_click.js.new
var title_page =  _L("background_add_page_url");
var id_page = chrome.contextMenus.create({
    'title': title_page, 'contexts':['page'], 'onclick': function(OnClickData,tab){
        var tmp = $.trim(OnClickData.pageUrl);
        if(tmp.length > 225){
            alert(_L('TASK_VALI_TITLE_TOO_LONG'));
            return;
        }else{
            var task = {
                uuid:makeUUID(),
                title : tab.title,
                notes : tmp,
                start_at : null,//要拼凑
                completed : null,
                all_day : true,
                attribute: 'inbox'
            }
            postTask(task,function(t){
                alert(_L('Success'));
            });
        }
        //alert('page '+OnClickData.pageUrl);
    }
});
mercari
フリマアプリ「メルカリ」を、グローバルで開発しています。
https://tech.mercari.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした