-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDreamBeerPrint.js
More file actions
74 lines (64 loc) · 2.78 KB
/
DreamBeerPrint.js
File metadata and controls
74 lines (64 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// ==UserScript==
// @name Dream Beer print screen
// @namespace http://tampermonkey.net/
// @version 2025-06-08
// @description プリント用PDFを生成
// @author octan
// @match https://dreambeer.jp/ec/beer/detail/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=dreambeer.jp
// @require https://github.com/0ctan/pdfmake-jp/raw/refs/heads/master/build/pdfmake.min.js
// @require https://github.com/0ctan/pdfmake-jp/raw/refs/heads/master/build/vfs_fonts.js
// @require https://cdn.jsdelivr.net/npm/html-to-pdfmake/browser.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
// ボタン追加
window.onload = function(){
const elms = document.getElementsByClassName('product_info_holder');
const child = document.createElement('button');
const str = document.createTextNode("印刷用PDFをDL");
child.appendChild(str);
child.setAttribute('class', 'createpdfButton');
elms[0].appendChild(child);
};
// htmlパース
let beername = document.getElementsByTagName('h1')[1];
let glassimg = document.getElementsByTagName('img')[4];
let labelimg = document.getElementsByTagName('img')[5];
let txt = document.getElementsByClassName('product_decs noto-san')[0];
let type = document.getElementsByClassName('beer_type_text popup_beerstyle_btn break_long_text')[0];
let price = document.getElementsByClassName('product_price__price__number')[0];
let info = document.getElementsByClassName('info_table')[0];
let detail = document.getElementsByClassName('detail_info_left')[0];
let chart = document.getElementsByClassName('detail_info_right')[0];
let breweryname = document.getElementsByClassName('brewery_name')[0];
let brewerytxt = document.getElementsByClassName('content_text')[1];
let foodpair = document.getElementsByClassName('food_pairing_right')[1];
let foodpairtitle = document.getElementsByClassName('food_pairing_left')[0];
let foodimg = document.getElementsByClassName('food_pairing_left')[1];
let foodtag = document.getElementsByClassName('list_tag')[0];
const html = beername.object //strに変換
// PDF生成
function createPDF() {
pdfMake.fonts = {
NotoSans: {
normal: 'NotoSansJP-Regular.ttf'
}
};
const docDefinition = {
content: [
(htmlToPdfmake(html))
],
defaultStyle: {
font: 'NotoSans',
},
};
pdfMake.createPdf(docDefinition).download('beerprint.pdf');
console.log(docDefinition);
};
//イベントハンドラ
$(document).on('click', '.createpdfButton', function() {
createPDF();
});
})();