とりあえず用ブックマークレット 商品ページと商品 イメージの印刷最適化

Quick Edit Pencil
javascript:

/* -----------------------------------------------
とりあえず商品ページ印刷最適化ブックマークレット
TAGO.OKに投稿してる
https://tagook.blogspot.com/
----------------------------------------------- */

/*タイトルを変更*/
document.title = document.title.replace(/商品画像│|商品ページ│/g, '');
document.title = '商品ページ│' + document.title;

/*スコットランド国立博物館*/
function nms_ac_uk(){
    /*スタイルとスクリプト削除*/
    var styleElms = document.querySelectorAll(".siteSearch");
    for (var i = 0; i < styleElms.length; i++) {
      console.log(styleElms[i]);
      styleElms[i].remove();
    }

    /*スタイル要素を追加*/
    var body = document.getElementsByTagName('body').item(0);
    var style = document.createElement('style');
    var text = text = `
    @media print 
    {
      a[href]:after { content: none !important; }
      img[src]:after { content: none !important; }
      abbr[title]:after { content: none !important; }
    }
    @media print 
    {
      .siteHead__logo img { width: 196px; height: auto; }
    }
    `;
    var rule = document.createTextNode(text);
    /*style.media = 'screen';*/
    style.type = 'text/css';
    style.appendChild(rule);
    body.appendChild(style);
}

nms_ac_uk();

/*プリンtダイアログを開く*/
window.print();


javascript:

/* -----------------------------------------------
とりあえず商品イメージ印刷最適化ブックマークレット
TAGO.OKに投稿してる
https://tagook.blogspot.com/
----------------------------------------------- */

/*タイトルを変更*/
document.title = document.title.replace(/商品画像│|商品ページ│/g, '');
document.title = '商品画像│' + document.title;


/*スタイルとスクリプト削除*/
var styleElms = document.querySelectorAll("link,style,script,noscript");
for (var i = 0; i < styleElms.length; i++) {
  console.log(styleElms[i]);
  styleElms[i].remove();
}


/*サムネイルのソースを配列に格納*/
var arrImgSrc = new Array();

/* デフォルト */
function imageSrc_to_array_0(){
    var imagesSrc = document.querySelectorAll("#gallery1 img");
    for (var i = 0; i < imagesSrc.length; i++) {
      console.log(imagesSrc[i].src);
      arrImgSrc.push(imagesSrc[i].src);
    }
}

/* Classic Camp Stoves */
function imageSrc_to_array_1(){
    /*https://classiccampstoves.com/threads/primus-stove-ultraprimus-soldering-iron-furnace-c-1895.39320/*/
    var imagesSrc = document.querySelectorAll("img.bbCodeImage.LbImage,a.LbTrigger");
    for (var i = 0; i < imagesSrc.length; i++) {
      if(imagesSrc[i].tagName == "IMG" && /show the full-size version/.test(imagesSrc[i].title)){
        console.log(imagesSrc[i].src);
        arrImgSrc.push(imagesSrc[i].src);
      }else if(imagesSrc[i].tagName == "A") {
      console.log(imagesSrc[i].href);
      arrImgSrc.push(imagesSrc[i].href);
      }
    }
}

/* スコットランド国立博物館 */
function imageSrc_to_array_2(){
    var imagesSrc = document.querySelectorAll(".collectionLightbox img");
    for (var i = 0; i < imagesSrc.length; i++) {
      console.log(imagesSrc[i].src);
      arrImgSrc.push(imagesSrc[i].src);
    }
}

imageSrc_to_array_2();



/*ボディを初期化*/
var body = document.body;
body.innerHTML = "";
body.removeAttribute('class');


/*印刷用イメージ要素をクリエイト*/
var img_element;
for (var i = 0; i < arrImgSrc.length; i++) {
  console.log(arrImgSrc[i]);
  img_element = document.createElement('img');
    img_element.src = arrImgSrc[i].replace('s-l64', 's-l1600');
    body.appendChild(img_element);
}


/*スタイル要素を追加*/
var style = document.createElement('style');
var text = `
/*画像調整*/
img
{width:100%;height:auto;padding-top:1px;}
/*非表示*/
button
{display:none!important;}
`;
var rule = document.createTextNode(text);
/*style.media = 'screen';*/
style.type = 'text/css';
style.appendChild(rule);
body.appendChild(style);


/*クリップボードに商品名をコピーして印刷ダイアログを開く*/
async function copyToClipboard(text) {
  try {
    await navigator.clipboard.writeText(text);
    console.log('コピーしました');
    /*プリンtダイアログを開く*/
    /*window.print();*/
  } catch (error) {
    alert((error && error.message) || 'コピーに失敗しました');
  }
}
copyToClipboard(document.title);

このブログの人気の投稿

PowerShellのGetDetailsOf メソッドでプロパティの詳細情報のID番号と項目名を列挙します

書字方向 横書方向変換スクリプト 左書きから右書きへ(コピペ用途)

PowerShellで複数ファイルのプロパティを取得する方法(準備編)

DOMノードオブジェクトを文字列に変換する

簡単 YouTube動画をダウンロード、音声のみ保存する方法 2019

AppleScript 改行 コード 置換

Blender: 辺の長さを数値で指定するアドオン

Powershell: プロパティの詳細情報インデックスと項目名の列挙