Changeset 19029

Show
Ignore:
Timestamp:
09/09/08 02:46:02 (5 years ago)
Author:
drry
Message:
  • fixed an invalid lang attribute.
  • fixed regexps.
  • et cetera.
Location:
lang/javascript/CvT
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/CvT/comment_via_twitter.user.js

    r14591 r19029  
    33// @namespace      com.mesolabs 
    44// @description    Comment via Twitter 
    5 // @include        * 
     5// @include        http://* 
     6// @include        https://* 
     7// @include        ftp://* 
    68// ==/UserScript== 
    79 
     
    1113    var twitterId; 
    1214    var cvtElement = document.getElementById("_cvt_twitterId"); 
    13      
     15 
    1416    if (cvtElement && cvtElement.textContent) { 
    1517        twitterId = cvtElement.textContent; 
     
    1719    } else { 
    1820        var href1 = document.location.href; 
    19         var href2 = href1.match(/\/$/) ? href1.replace(/\/$/, "") : href1 + "/"; 
     21        var href2 = href1.match(/\/$/) ? href1.replace(/\/+$/, "") : href1 + "/"; 
    2022 
    2123        // tako3から取得 
     
    2931        load(foooUrl + href2); 
    3032    } 
    31      
     33 
    3234    function load(url) { 
    3335        GM_xmlhttpRequest({ 
    3436            method: "GET", 
    3537            url:    url, 
    36             onload: function(res){ 
    37                 if(!twitterId) { 
     38            onload: function(res) { 
     39                if (!twitterId) { 
    3840                    eval(res.responseText); 
    39                     if(twitterId) { 
     41                    if (twitterId) { 
    4042                        showForm(); 
    4143                    } 
     
    4446        }); 
    4547    } 
    46      
     48 
    4749    function tako3(response) { 
    48         for (var i = 0; i < response.length; i++) { 
     50        for (var i = 0, l = response.length, url; i < l; i++) { 
    4951            url = response[i]; 
    50             if (url.match(/http:\/\/twitter.com\/.*/)) { 
    51                 url = url.match(/\/$/) ? url.replace(/\/$/, "") : url; 
    52                 tmp = url.replace(/http:\/\/twitter.com\//, ""); 
    53                 if (tmp != "home") { 
    54                     twitterId = tmp; 
    55                 } 
     52            if (/https?:\/\/twitter\.com\/([^\/]+)/.test(url) && 
     53                RegExp.$1 != "home") { 
     54                twitterId = RegExp.$1; 
    5655            } 
    5756        } 
    5857    } 
    59      
     58 
    6059    function showForm(twitterId) { 
    6160        var form = // 
    6261        <form action="#" id="_cvt_form"> 
    63             Comment via Twitter: <input type="text" id="_cvt_text" /> 
    64             <input type="button" value="投稿" id="_cvt_submit" /> 
     62            Comment via Twitter: <input type="text" id="_cvt_text"/> 
     63            <input type="button" value="投稿" id="_cvt_submit"/> 
    6564        </form>; 
    6665 
     
    101100    function submit() { 
    102101        var status = encodeURIComponent( 
    103             "@" + twitterId + " (" + document.location.href + ") " +  
     102            "@" + twitterId + " <" + document.location.href + "> " + 
    104103            document.getElementById("_cvt_text").value); 
    105104        var url = "http://twitter.com/statuses/update.json"; 
     
    111110            data: "status=" + status, 
    112111            headers: { 
    113                 "Content-Type":"application/x-www-form-urlencoded", 
     112                "Content-Type": "application/x-www-form-urlencoded", 
    114113                "X-Twitter-Client": "Comment via Twitter", 
    115                 "X-Twitter-Client-Version": "0.1" 
     114                "X-Twitter-Client-Version": "0.1", 
     115                "User-Agent": "Comment-via-Twitter/0.1 (Greasemonkey)" 
    116116            }, 
    117117            onload: function(xhr) { 
  • lang/javascript/CvT/test.html

    r14528 r19029  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
    2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> 
     2<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja"> 
    33    <head> 
    44        <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> 
     
    66    </head> 
    77    <body> 
    8          
     8 
    99       <div id="_cvt_twitterId" style="visibility: hidden;">meso</div> 
    1010    </body>