2017-03-10 7 views
0

はどういうわけか、このuserscriptではなく、子の親に属性を追加するようだ:jQueryの一人っ子に追加

が私を助けてくださいcは、それはそれをやっている理由を理解するために:

// ==UserScript== 
// @name  GMod Cinema Porn 
// @namespace Bluscream 
// @version  1.0 
// @description H3H3 
// @author  Bluscream 
// @include  https://www.youtube.com/embed/OiMTuwS3xvg* 
// @include  http://cinema.pixeltailgames.com/search.html 
// @include  * 
// @grant  unsafeWindow 
// @grant  GM_xmlhttpRequest 
// @require  https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js 
// @run-at  document-end 
// ==/UserScript== 
(function() { 
    'use strict'; 
    if (window.location.href.startsWith("https://www.youtube.com/embed/OiMTuwS3xvg")) { 
     window.location.href = "http://embed.redtube.com/player/?id=42019&autostart=true"; 
    } else if (window.location.href == "http://cinema.pixeltailgames.com/search.html"){ 
     $ = jQuery || $; 
     $(document).ready(function() { 
      temop = $('#content-container').children('div[style="text-align:center;font-size:0;"]:first'); 
      temop.append('<service>').css('background-image', 'url("http://cdn1-www.craveonline.com/assets/uploads/2013/12/man_file_1048340_youporn-icon.png")').click(function() { 
       window.selectService("YouPorn", "http:\/\/www.youporn.com"); 
      }).hover(function() { 
       window.hoverService(); 
      }); 
     }); 
     //$('#content-container>div[style="text-align:center;font-size:0;"]').append('<service style=\'background-image:url(\"logos\/youtube.png\")\' onclick=\'selectService(\"YouTube\",\"http:\/\/www.youtube.com\")\' onmouseover="hoverService()">-</service>'); 
    } 
})(); 

答えて

1

oをjQueryの要素ので、 .append()を使用すると、直前に追加された要素ではなく、直前の要素が返されます。

属性を適用する前に、追加された要素を対象にする必要があります。&イベントリスナー。このようなもの:

temop 
    .append('<service>') 
    .find('service:last') 
    .css(/* ... */) 
    .click(/* ... */) 
    .hover(/* ... */); 
+0

Du hier?ダンケ:) – Bluscream

関連する問題