「MediaWiki:Common.js」の版間の差分

提供:作業療法大百科事典OtWiki
編集の要約なし
編集の要約なし
1行目: 1行目:
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */


document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('DOMContentLoaded', function() {
     // 現在のページのURLを取得
     // 現在のページのURLを取得
     var currentPageUrl = window.location.href;
     var currentPageUrl = window.location.href;
   
    // Pocketボタンを取得
    var pocketButton = document.querySelector('#footer-places-snsbuttonPocket a');
    // Pocketのシェア用URLを設定
    var pocketShareUrl = 'https://getpocket.com/save?url=' + encodeURIComponent(currentPageUrl);
    // href属性にURLを設定
    pocketButton.href = pocketShareUrl;


// Facebookボタンを取得
     // Twitterボタンを取得
     var facebookButton = document.querySelector('#footer-places-snsbuttonFacebook a');
 
    // Facebookのシェア用URLを設定
    var facebookShareUrl = 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(currentPageUrl);
 
    // href属性にURLを設定
    facebookButton.href = facebookShareUrl;
 
// Twitterボタンを取得
     var twitterButton = document.querySelector('#footer-places-snsbuttonX a');
     var twitterButton = document.querySelector('#footer-places-snsbuttonX a');


     // Twitterのシェア用URLを設定
     // URLが正しく取得できたかを確認
    var twitterShareUrl = 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(currentPageUrl) + '&text=' + encodeURIComponent(document.title);
    if (twitterButton) {
 
        // Twitterのシェア用URLを設定
    // href属性にURLを設定
        var twitterShareUrl = 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(currentPageUrl) + '&text=' + encodeURIComponent(document.title);
    twitterButton.href = twitterShareUrl;


        // href属性にURLを設定
        twitterButton.href = twitterShareUrl;
    } else {
        console.error("Twitterボタンが見つかりませんでした。");
    }
});
});

2024年5月29日 (水) 22:04時点における版

/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */

document.addEventListener('DOMContentLoaded', function() {
    // 現在のページのURLを取得
    var currentPageUrl = window.location.href;

    // Twitterボタンを取得
    var twitterButton = document.querySelector('#footer-places-snsbuttonX a');

    // URLが正しく取得できたかを確認
    if (twitterButton) {
        // Twitterのシェア用URLを設定
        var twitterShareUrl = 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(currentPageUrl) + '&text=' + encodeURIComponent(document.title);

        // href属性にURLを設定
        twitterButton.href = twitterShareUrl;
    } else {
        console.error("Twitterボタンが見つかりませんでした。");
    }
});