« 夏の昼飯代表チャーハンつくった | メイン | powwow Tシャツ展を終えてmac bookを買うことに »



SharePointのライブラリにアイテムを突っ込むgreasemonkey作った

SharePointのライブラリにアイテムを突っ込むgreasemonkey作ったをはてなブックマークに追加 SharePointのライブラリにアイテムを突っ込むgreasemonkey作ったをdel.icio.usに追加  Yahoo!ブックマークに登録 SharePointのライブラリにアイテムを突っ込むgreasemonkey作ったをGoogle Bookmarksに追加 SharePointのライブラリにアイテムを突っ込むgreasemonkey作ったをtwitterにポスト
SharePointのライブラリにアイテムを突っ込むgreasemonkey作りました。SharePointライブラリはSBMみたいな扱いで、設定は以下のように作る必要があります。
  • フィールド名:link, 複数行テキスト:拡張リッチテキスト
  • フィールド名:tag, 1行テキスト
  • フィールド名:comment, 複数行テキスト:書式なしテキスト
コンフィグなどで環境にあわせられるようにしたかったのですがやってません。greasemonkey側の環境設定は以下のようにスクリプトを書き換えてあげる必要があります(ノ∀`)ダハー
  • [#hostheader]→自分の環境のホストヘッダをいれます。
  • [#site]→サイトが入ります。ライブラリを作ったサイトURLが入ります。
  • [#lib name]→ライブラリ名が入ります。
shift-bでプロンプトがあがります。タグを入力すると、ブラウジング中のURLとタイトルをライブラリに突っ込むのですが、プロンプトに"@/@"アットマークに続く文字列を入力すると、コメントとして扱います。shift-bがほかのイベントと競合する場合は以下の部分を変えてあげるだけです。
    keybind( "S-b", popPrompt ); 
e.g)
javascript greasemonkey @コメントほげほげ
→javascript, greasemonkeyがタグとして扱われ、コメントほげほげがコメントとして扱われます。
SharePointのフォームをいちいち開かなくてもポコポコアイテムを突っ込めるので意外と便利です。
spsbm.user.js
// ==UserScript==
// @name           spsbm
// @namespace      http://[#hostheader]
// @include        *
// ==/UserScript==
(function(){
    var keybind = ( function(){
        function add ( phrase, func ){
            if( phrase instanceof Array ){
                phrase.forEach( function( p ){ add( p, func ); });
            }
            else {
                document.addEventListener(
                    "keydown",
                    function( event ){
                        var tagName = event.target.tagName;
                        if( phrase == code( event ) && !tagName.match( /(INPUT|TEXTAREA)/i ) ){
                            func();
                            event.preventDefault();
                            event.stopPropagation();
                        }
                    },
                    true
                );
            }
        }
        
        function code( event ){
            var code = [];
            if( event.shiftKey ){
                code.push( "S" );
            } 
            else if( event.ctrlKey ){
                code.push( "C" );
            } 
            else if( event.altKey || event.metaKey ){
                code.push( "M" );
            }
            code.push( kc2char( event.keyCode ) );
            return code.join("-");

            function kc2char( kc ){
                function between( a, b ){
                    return a <= kc && kc <= b;
                }
                var _32_40 = "space pageup pagedown end home left up right down".split(" ");
                var kt = {
                    8  : "backspace",
                    9  : "tab"  ,
                    13 : "enter",
                    16 : "shift",
                    17 : "control",
                    27 : "escape",
                    46 : "delete",
                };
                return ( between( 65, 90 )  ? String.fromCharCode( kc + 32 ) :
                         between( 48, 57 )  ? String.fromCharCode( kc ) :
                         between( 96, 105 ) ? String.fromCharCode( kc - 48 ) :
                         between( 32, 40 )  ? _32_40[ kc - 32 ] :
                         kt.hasOwnProperty( kc ) ? kt[ kc ] :
                         kc
                );
            }
        }
        return add;
    })();

    function popPrompt(){
		var comment = '';
        var tags = prompt( 'ブクマタグを入力してください(デリミタ半角スペース)', '' );

        if( tags == null || tags.length == 0 ) return;

        var aryBuf = tags.replace( /^\s+|\s+$/g, '' ).split( ' ' );
		var tagList = [];
		for( var idx = 0; idx < aryBuf.length; idx++ ){
			var str = aryBuf[ idx ];
			if( str.length == 0 ) continue;
		    if( str.indexOf( str.match( /^@|^@/ ), 0 ) == 0 ){
				comment = comment + str.replace( /^@|^@/, '' );
				continue;
			}
			tagList.push( str );
		}

        var sendXml = '';
        for( var idx = 0; idx < tagList.length; idx++ ){
            sendXml = sendXml + 
            '<Method ID="' + ( idx + 1 ) + '" Cmd="New">' +
            '<Field Name="link">' + '&lt;a href="' + document.location.href + '"&gt;' + document.title + '&lt;/a&gt;' +'</Field>' + 
            '<Field Name="tag">' + tagList[ idx ] + '</Field>' + 
            '<Field Name="Title">' + document.title + '</Field>' + 
            '<Field Name="comment">' + comment + '</Field>' + 
            '</Method>';
        }
        sendXml = '<Batch>' + sendXml + '</Batch>';

        GM_xmlhttpRequest({
            method : 'POST',
            url : 'http://[#hostheader]/[#site]/_vti_bin/Lists.asmx',
            headers : {
                'Content-Type' : 'text/xml; charset=utf-8',
                'SOAPAction' : 'http://schemas.microsoft.com/sharepoint/soap/UpdateListItems' 
            },
            data : '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"><listName>[#lib name]</listName><updates>' + sendXml + '</updates></UpdateListItems></soap:Body></soap:Envelope>',
            onload : function( response ) {
                var msg = ( response.responseText.length == 0 ) ? 'ブクマ失敗' : 'ブクマしました';
                alert( msg + '\n\nvia:\nhttp://[#hostheader]/[#site]/Lists/[#lib name]/AllItems.aspx' );
            }
        });
    }
    keybind( "S-b", popPrompt ); 
})();

★このコンテンツに目的の情報はありませんでしたか?


[ 最近のエントリーとその関連エントリー ]


[ スポンサードリンク ]

トラックバック

このエントリーのトラックバックURL:
http://mojalog.com/cgi/mt/mt-tb.cgi/321

コメントを投稿

ツリータイプ・カテゴリー

open all | close all

リファラから検索


サイト内検索