IT |
ITmedia 総合記事一覧 |
[ITmedia エグゼクティブ] 「宇宙はエキサイティングな時代に」 星出さん会見 |
https://mag.executive.itmedia.co.jp/executive/articles/2202/07/news056.html
|
itmedia |
2022-02-07 08:31:00 |
TECH |
Techable(テッカブル) |
あの名シーンがNFTに! ミクシィとDAZN、スポーツ特化型NFTマーケットプレイス提供へ |
https://techable.jp/archives/172944
|
daznjapaninvestment |
2022-02-06 23:00:30 |
AWS |
AWSタグが付けられた新着投稿 - Qiita |
Amazon Route 53とAWS WAFとAmazon CloudFrontとAmazon S3で独自ドメインホスティング環境を構築してみた |
https://qiita.com/dayjournal/items/945613577b3056ec4f71
|
作成後、Sのバケットを確認するとポリシーが自動で設定されているのを確認。 |
2022-02-07 08:10:21 |
Docker |
dockerタグが付けられた新着投稿 - Qiita |
nginxの設定を理解し、.htmlファイルの中のphpを実行できるようにした |
https://qiita.com/rapsody0919/items/b8b0b123b142b325fe91
|
locationディレクティブマッチするURIごとのコンテキストを定義パスの評価方法には下記の種類がある前方一致正規表現indextryfileserrorpageinternaluri内部リダイレクトについてプレフィックス本題phpfpmでhtmlの中のphp部分を実行させたい場合、下記を記載したphpfpmの設定ファイルを作成し、volumeとしてphpfpmのusrlocaletcphpfpmdwwwconfにマウントしてあげる。 |
2022-02-07 08:20:26 |
Docker |
dockerタグが付けられた新着投稿 - Qiita |
JavaのSeleniumテストがDockerコンテナを起動・停止できるようにした |
https://qiita.com/kazurayam/items/4ccf9f70fb43455c8db1
|
Seleniumテストのためにlocalhost上でWebサーバを動かしたいが、そのためにDockerコンテナを起動・停止するのをJUnitテストの一部としてJavaコードから実行したい。 |
2022-02-07 08:06:11 |
golang |
Goタグが付けられた新着投稿 - Qiita |
ズボラで面倒くさがりな人に向けた git-commit message linter |
https://qiita.com/masahiro331/items/241a562af1810ad9e4fe
|
普段ContributeしているOSSについにCONTRIBUTINGmdcommitmessageの規約とか書いてるやつが追加されたため、もうちゃんとするしか無いじゃんでもlinterとかよくわからんってなった結果、自作で最小機能のlinterを作りました。 |
2022-02-07 08:22:42 |
Git |
Gitタグが付けられた新着投稿 - Qiita |
ズボラで面倒くさがりな人に向けた git-commit message linter |
https://qiita.com/masahiro331/items/241a562af1810ad9e4fe
|
普段ContributeしているOSSについにCONTRIBUTINGmdcommitmessageの規約とか書いてるやつが追加されたため、もうちゃんとするしか無いじゃんでもlinterとかよくわからんってなった結果、自作で最小機能のlinterを作りました。 |
2022-02-07 08:22:42 |
技術ブログ |
Developers.IO |
IAMサービスにおけるアクセス権限の管理アクション早見表 |
https://dev.classmethod.jp/articles/aws-iam-permissions-management-action/
|
自分 |
2022-02-06 23:30:03 |
技術ブログ |
Developers.IO |
UIKitからSwiftUIへの移行の第一歩を踏み出してみた |
https://dev.classmethod.jp/articles/first-step-uikit-to-swiftui/
|
stroyboard |
2022-02-06 23:00:49 |
技術ブログ |
Developers.IO |
セブに移住しようとしたが、色々あって長野にログハウス借りて住んでる人の話 |
https://dev.classmethod.jp/articles/emigrate-to-anywhere/
|
長野県富士見町 |
2022-02-06 23:00:29 |
海外TECH |
DEV Community |
Create a Google Chrome Extension Part 1: Image Grabber |
https://dev.to/andreygermanov/create-a-google-chrome-extension-part-1-image-grabber-1foa
|
Create a Google Chrome Extension Part Image Grabber IntroductionChrome Extensions are small programs that can be installed to Google Chrome web browser to enrich its features Usually to install a Chrome Extension a user should open Chrome Web Store find the required extension and install it from there In this article I will show how to create a Chrome Extension from scratch The extension which we will create today will use Chrome APIs to get access to the content of web pages which opened in a web browser and extract different information from them Using these APIs you can not only read content from web pages but also write content to them and interact with these pages like for example automatically pressing buttons or following links This feature can be used for a wide range of browser automation tasks like scrapping required information from websites or automating web surfing which can be useful to automate user interface testing In this article I will guide you through the process of building an extension named Image Grabber The resulting extension will provide an interface to connect to a website read all images from it grab their absolute URLs and copy these URLs to a clipboard During this process you will know about foundational parts of the Google Chrome extension that can be reused to build an extension of any kind By the end of this article you will build an extension that looks and works as shown in this video However this is only the first part of the tutorial In the second part I will show how to modify the extension to create an interface that will use the list of retrieved image URLs to automatically download all or selected images as a single ZIP archive So let s get started Basic extension structureGoogle Chrome Extension is a web application that can contain any number of HTML pages CSS stylesheets JavaScript files images any other files and a special manifest json file in the same folder which defines how this particular extension will look and work Minimal Chrome extensionMinimal Chrome Extension consists only of the manifest json file This is an example of a basic manifest json file that can be used as a template when start creating any new Chrome extension name Image Grabber description Extract all images from current web page version manifest version icons action permissions background The only required fields are name description version and manifest version manifest version should be equal to Values of other fields are up to you they should clearly describe your extension and its version In this example I described the Image Grabber extension which will extract links of all images from a current browser page You can see a full list of options that can be specified in the manifest json file in the official documentation A folder with a single manifest json file is a minimal runnable Chrome Extension that can be packaged installed to Chrome and distributed This minimal extension will have a default look and will do nothing until we define other fields icons action permissions and background So let s create the image grabber folder and put the manifest json file with that default content Then let s just install this extension to Chrome Install Chrome ExtensionWhen you develop an extension it has a form of a folder with files In Chrome extensions terms it is called unpacked extension After you finish development you will need to pack the extension folder to a special archive with a crx extension using the Chrome extensions manager This archive then can be used to upload to Chrome Web Store from which users can install it to their browsers To test and debug extension during development you can install unpacked extension to Chrome To do this type chrome extensions in the browser s URL string to open the Chrome Extensions Manager To install and debug extensions during development turn on the Developer mode switch on the right side of the Extensions panel It will show extensions management panel Then press the Load unpacked button and select a folder with the extension Point it to our minimal image grabber extension Right after this a panel for the Image Grabber extension will appear in a list of installed extensions The Image Grabber extension panel shows a unique ID description and version of the extension Every time when changing the manifest json file you need to press the Reload icon on the extension panel to reload the updated extension To use the extension in the browser you can find it in a list of Chrome installed extensions To see this list press the Extensions icon button on the right side of the Chrome URL bar and find the Image Grabber item in the dropdown list You can also press the Pin icon button at the right side of the extension to place an icon of the extension to the browser toolbar on the same line with other common extensions After Pin the extension its default icon will appear on the toolbar That s all We installed the minimal working Chrome extension However it looks like a simple I symbol on a gray background and nothing happens when you click on it Let s add other missing parts to the manifest json to change this Add extension iconsThe icons field in the manifest json file has a format of Javascript object which defines locations of icons of various sizes Extension should have icons of different sizes x px x px x px and x px Icons are PNG images that should be placed anywhere in the extension folder Image files can have any names I have created icons of appropriate sizes in png png png and png files and put them into the icons folder inside the extension root folder Then manifest json should be pointed to these locations using the icons field in a way as shown below name Image Grabber description Extract all images from current web page version manifest version icons icons png icons png icons png icons png action permissions background Paths to icon files are specified as relative paths After this is done press the Reload button on the Image Grabber extension panel on the chrome extensions tab to apply changed manifest json As a result you should see that the icon of the extension on the toolbar changed as displayed below Now it looks better but if you press this icon nothing happens Let s add actions to this extension Create the extension interfaceAn extension should do something it should run some actions to have a sense The extension allows to run actions in two ways In the background when extension startsFrom an interface of the extension when a user interacts with it using buttons or other UI controlsThe extension can use both options at the same time To run actions in the background you have to create a JS script and specify its location in the background field of manifest json This script can define listeners for a wide range of browser events for example when the extension is installed when a user opens closes a tab in a browser when the user adds removes a bookmark and many others Then this script will run in the background all the time and react to each of these events by running Javascript code from event handling functions For this extension I will not use this feature so the background field of manifest json will be empty It s included only to make the manifest json file to be useful as a starting template for a Chrome extension of any kind but in the Image Grabber extension the only action is Grab images and it will run only from a user interface when the user explicitly press the GRAB NOW button To run actions from the interface we need to define an interface Interfaces for Chrome extensions are HTML pages which can be combined with CSS stylesheets to style these pages and Javascript files which define actions to run when the user interacts with elements of that interface The main interface is an interface displayed when the user clicks on the extension icon on the toolbar and it should be defined in the action field of the manifest json file Depending on how the interface is defined it can be opened as a new tab in the browser or displayed as a popup window below the extension button when the user presses it The Image Grabber extension uses the second option It displays a popup with a header and the GRAB NOW button So let s define this in the manifest json name Image Grabber description Extract all images from current web page version manifest version icons icons png icons png icons png icons png action default popup popup html permissions background So as defined here the main interface is a popup window and the content of this popup window should be in the popup html file This file is an ordinary HTML page So create the popup html file in the extension folder with the following content lt DOCTYPE html gt lt html gt lt head gt lt title gt Image Grabber lt title gt lt head gt lt body gt lt h gt Image Grabber lt h gt lt button id grabBtn gt GRAB NOW lt button gt lt body gt lt html gt This is a simple page with the Image Grabber header and the GRAB NOW button which has a grabBtn id Go to chrome extensions to reload the Image Grabber extension Now you can press the extension icon to see the popup window with the interface It works but looks not enough perfect Let s style it using CSS Create the following popup css file in the extension folder body text align center width px button width color white background linear gradient ae bcbc border width px border radius px padding px font weight bold cursor pointer This CSS defines that the body should have a width of px This way the size of the popup window should be defined for a Chrome extension If not defined then the extension will use a minimum size required to display the content Then add this popup css stylesheet to the header of the popup html page lt DOCTYPE html gt lt html gt lt head gt lt title gt Image Grabber lt title gt lt link rel stylesheet type text css href popup css gt lt head gt lt body gt lt h gt Image Grabber lt h gt lt button id grabBtn gt GRAB NOW lt button gt lt body gt lt html gt So when all this is in place you can click on the extension icon again to see the styled popup window As you could notice you do not need to reload extension every time when modify HTML or any other file You have to reload the extension only when change the manifest json Now to make our UI complete let s add a Javascript code to react on the GRAB NOW button click event Here is one important note Chrome does not allow to have any inline Javascript in HTML pages of extensions All Javascript code should be defined only in separate js files That is why create a popup js file in the extensions folder with the following placeholder code const grabBtn document getElementById grabBtn grabBtn addEventListener click gt alert CLICKED and include this script file to the popup html page lt DOCTYPE html gt lt html gt lt head gt lt title gt Image Grabber lt title gt lt link rel stylesheet type text css href popup css gt lt head gt lt body gt lt h gt Image Grabber lt h gt lt button id grabBtn gt GRAB NOW lt button gt lt script src popup js gt lt script gt lt body gt lt html gt This code adds the onClick event listener to a button with grabBtn ID Now if you open the extension popup and click the GRAB NOW button it should display an alert box with CLICKED text Finally we have a complete layout of an extension with a styled interface and event handling script for it At the current stage this is an extension that can be used as a base template to start building a wide range of Chrome extensions based on a popup user interface Now let s implement a business logic of this concrete extension the onClick handler for the GRAB NOW button to get a list of image URLs from the current browser page and copy it to a clipboard Implement the GRAB NOW functionUsing Javascript in extension you can do everything that you can do using Javascript on a website open other HTML pages from current one make requests to a remote servers upload data from extension to the remote locations and whatever else But in addition to this if this script executed in a chrome extension you can use Chrome browser APIs to communicate with the browser objects to read from them and to change them Most of Google Chrome APIs available through chrome namespace In particular for Image Grabber extension we will use the following APIs chrome tabs Chrome Tabs API It will be used to access an active tab of the Chrome browser chrome scripting Chrome Scripting API It will be used to inject and execute JavaScript code on a web page that opened in the active browser tab Obtain required permissionsBy default for security reasons Chrome does not permit access to all available APIs The extension should declare which permissions it requires in the permissions field of the manifest json There are many permissions that exist all they described in the official documentation here For Image Grabber we need two permissions with the following names activeTab to obtain access to the active tab of a browserscripting to obtain access to the Chrome Scripting API to inject and execute JavaScript scripts in different places of the Chrome browser To obtain those permissions need to add their names to the permissions array field of the manifest json name Image Grabber description Extract all images from current web page version manifest version icons icons png icons png icons png icons png action default popup popup html permissions scripting activeTab background This is a final manifest json for this project Now it has all required parts icons link to the main interface popup interface and the permissions that this interface requires Get information about the active browser tabTo query information about browser tabs we will use the chrome tabs query function which has the following signature chrome tabs query queryObject callback The queryObject is a Javascript object with fields that define search criteria for browser tabs which we need to get The callback is a function that is called after the query is complete This function is executed with a single parameter tabs which is an array of found tabs that meet specified search criteria Each element of the tabs array is aTab object The Tab object describes the found tab and contains a unique ID of the tab its title and other information Here I will not completely describe queryObject format and the returned Tab object You can find this information in a chrome tabs API reference here For the purpose of the Image Grabber extension we need to query the tab which is active The query to search this kind of tab is active true Let s write a code to get information about the active tab to the GRAB NOW button onClick handler const grabBtn document getElementById grabBtn grabBtn addEventListener click gt chrome tabs query active true tabs gt const tab tabs if tab alert tab id else alert There are no active tabs This code executes a query to get all tabs that are active After the query is finished it calls a callback with an array of found tabs in the tabs argument Only one tab can be active so we can assume that this is the first and only item of the tabs array If the active tab exists we show an ID of that tab in an alert box we will replace this alert with reasonable code in the next section However if there are no active tabs we alert the user about that Now if you open the extension and press the GRAB NOW button it should show an alert window with a numeric ID of the active tab In the next section we will use this ID to manipulate the content of a web page displayed on that tab Grab images from the current pageThe extension can communicate with open pages of the Chrome browser using Chrome Scripting JavaScript API located in the chrome scripting namespace In particular we will use this API to inject a script to a web page of the current tab execute this script and return the result back to the extension When running it has access to all content of a web page to which this script is injected The only function of chrome scripting API which is used for this extension is executeScript It has the following signature chrome scripting executeScript injectSpec callback injectSpecThis is an object of ScriptInjection type It defines where and how to inject the script target field of this object is used to specify where to inject the script the ID of the browser tab to which the script should be injected Then other fields of this object define how to inject the script The script can be injected as file or files in this case need to specify an array of Javascript files to inject The files should exist in the extension folder function in this case need to specify a function to inject The function should exist in the same popup js file The script which we need to inject will be used to get all images of a target page and return their URLs This is a small script so we will inject it as a function located in the same popup js file So injectSpec for this case will look like this target tabId tab id allFrames true func grabImages Here we use the id of the tab object that we received in the previous step as a target to inject script to Also there is a allFrames option set which tells that the injected script should be executed in each embedded frame of the target page if that page has embedded frames As a script we will inject a grabImages function which will be defined later callbackThe injected function will do actions on a target web page and on all embedded frames of this page each frame is a separate page as well and will return the result After this happens the extension will execute the callback function with returned results as an argument An argument of the function is an array of objects of InjectionResult type for each frame Each object contains the result field which is an actual result that the grabImages function returns Now let s join all parts together const grabBtn document getElementById grabBtn grabBtn addEventListener click gt chrome tabs query active true function tabs var tab tabs if tab chrome scripting executeScript target tabId tab id allFrames true func grabImages onResult else alert There are no active tabs function grabImages TODO Query all images on a target web page and return an array of their URLs function onResult frames TODO Combine returned arrays of image URLs join them to a single string delimited by carriage return symbol and copy to a clipboard Then this is how the grabImages function is implemented Executed on a remote browser page to grab all images and return their URLs return Array of image URLs function grabImages const images document querySelectorAll img return Array from images map image gt image src This function will run on a target web page so the document specified inside it is a document DOM node of a target web page This function queries a list of all img nodes from a document then converts this list to an array and returns an array of URLs image src of these images This is a very raw and simple function so as homework you can customize it apply different filters to this list cleanup URLS by removing query strings from them and so on to make a resulting list look perfect After this function is executed in each frame of the target web page result arrays will be combined and sent to the onResult callback function which could look like this Executed after all grabImages calls finished on remote page Combines results and copy a list of image URLs to clipboard param InjectionResult frames Array of grabImage function execution results function onResult frames If script execution failed on the remote end and could not return results if frames frames length alert Could not retrieve images from specified page return Combine arrays of the image URLs from each frame to a single array const imageUrls frames map frame gt frame result reduce r r gt r concat r Copy to clipboard a string of image URLs delimited by carriage return symbol window navigator clipboard writeText imageUrls join n then gt close the extension popup after data is copied to the clipboard window close Not all tabs that opened in the browser are tabs with web pages inside For example a tab with a list of extensions or a tab with browser settings are not tabs with web pages If you try to run a script with the document object on these tabs it will fail and return nothing That is why at the beginning of the onResult function we check the result and continue only if it exists Then we combine arrays of image URLs returned for each frame to a single array by using map reduce combination and then use window navigator clipboard API to copy joined to string array to a clipboard writeText function is asynchronous so we have to wait until it finishes by resolving a promise that it returns And when it is resolved we close the popup window of the extension I have explained only a single function of Chrome scripting API and only in the context of the Image Grabber extension You can see the full documentation for Chrome Scripting API to clarify all missing parts Code cleanupThe last thing that I would do with the code that handles the GRAB NOW onClick event is to extract a code that does chrome scripting to a separate function const grabBtn document getElementById grabBtn grabBtn addEventListener click gt Get active browser tab chrome tabs query active true function tabs var tab tabs if tab execScript tab else alert There are no active tabs Function executes a grabImages function on a web page opened on specified tab param tab A tab to execute script on function execScript tab Execute a function on a page of the current browser tab and process the result of execution chrome scripting executeScript target tabId tab id allFrames true func grabImages onResult And the final content of popup js is following const grabBtn document getElementById grabBtn grabBtn addEventListener click gt Get active browser tab chrome tabs query active true function tabs var tab tabs if tab execScript tab else alert There are no active tabs Execute a grabImages function on a web page opened on specified tab and on all frames of this page param tab A tab to execute script on function execScript tab Execute a function on a page of the current browser tab and process the result of execution chrome scripting executeScript target tabId tab id allFrames true func grabImages onResult Executed on a remote browser page to grab all images and return their URLs return Array of image URLs function grabImages const images document querySelectorAll img return Array from images map image gt image src Executed after all grabImages calls finished on remote page Combines results and copy a list of image URLs to clipboard param InjectionResult frames Array of grabImage function execution results function onResult frames If script execution failed on remote end and could not return results if frames frames length alert Could not retrieve images from specified page return Combine arrays of image URLs from each frame to a single array const imageUrls frames map frame gt frame result reduce r r gt r concat r Copy to clipboard a string of image URLs delimited by carriage return symbol window navigator clipboard writeText imageUrls join n then gt close the extension popup after data is copied to the clipboard window close ConclusionAfter this is done you can open any browser web page with images open the extension popup of the Image Grabber extension and click the GRAB NOW button Then paste the clipboard content to any text editor It should paste a list of absolute URLs of all images from that web page You can clone and use the full source code of this extension from my GitHub repository However I would recommend creating this extension from scratch while reading this article This is only the first part of the tutorial related to this extension In a second part I will use this list of image URLs to build an additional interface for this extension that will allow downloading all or selected images from this list as a single ZIP archive This is definitely more useful than just having a list of URLs in the clipboard Also I will show how to package the completed extension and upload it to the Chrome Web Store which will make it available for anyone So stay tuned and follow me to know when the second article is available After the second article I want to write more about Chrome extensions but the world of them and their use cases is so huge that I can t choose from which ones to start I need your help please write in comments which kind of extensions you want me to show how to develop and I will be happy to use your suggestions for the future articles about this |
2022-02-06 23:04:44 |
海外TECH |
CodeProject Latest Articles |
A simple web API Account Manager in .NET 6 |
https://www.codeproject.com/Articles/5324452/A-simple-web-API-Account-Manager-in-NET-6
|
account |
2022-02-06 23:26:00 |
海外科学 |
NYT > Science |
Climate Change Enters the Therapy Room |
https://www.nytimes.com/2022/02/06/health/climate-anxiety-therapy.html
|
skepticism |
2022-02-06 23:52:27 |
医療系 |
内科開業医のお勉強日記 |
成人市中肺炎においてインフルエンザ診断・治療はその後の臨床的アウトカムに影響を与える |
https://kaigyoi.blogspot.com/2022/02/blog-post_7.html
|
nbspインフルエンザ陽性と判定された患者は、陰性と判定された患者よりも抗ウイルス剤の投与頻度が高く、抗菌剤の投与頻度は低く、投与期間も短かった日vs日、pインフルエンザ陽性患者nが入院初日にオセルタミビルを投与された場合、日間の院内死亡率が低く調整オッズ比、CI、コストが低く調整平均比、CI、LOSも短く調整平均比、CI、オセルタミビルの投与時間が遅いか全く投与を受けないn患者と比べました。 |
2022-02-06 23:58:00 |
金融 |
日本銀行:RSS |
日本銀行の対政府取引(1月) |
http://www.boj.or.jp/statistics/boj/other/tseifu/release/2022/seifu2201.pdf
|
日本銀行 |
2022-02-07 08:50:00 |
金融 |
日本銀行:RSS |
マネタリーベースと日本銀行の取引(1月) |
http://www.boj.or.jp/statistics/boj/other/mbt/mbt2201.pdf
|
日本銀行 |
2022-02-07 08:50:00 |
金融 |
日本銀行:RSS |
オペレーション(1月) |
http://www.boj.or.jp/statistics/boj/fm/ope/m_release/2022/ope2201.xlsx
|
オペレーション |
2022-02-07 08:50:00 |
ニュース |
BBC News - Home |
Newspaper headlines: PM in crisis and NHS rescue plan delays |
https://www.bbc.co.uk/news/blogs-the-papers-60283370?at_medium=RSS&at_campaign=KARANGA
|
delaysmore |
2022-02-06 23:21:53 |
ビジネス |
ダイヤモンド・オンライン - 新着記事 |
メタが挑むいばらの道 最強TikTokを倒せるか - WSJ発 |
https://diamond.jp/articles/-/295514
|
tiktok |
2022-02-07 08:26:00 |
LifeHuck |
ライフハッカー[日本版] |
最小労力で最大利益を得る「80:20の法則」 |
https://www.lifehacker.jp/article/2202how-80-20-rule-revolutionize-productivity/
|
法則 |
2022-02-06 23:30:00 |
北海道 |
北海道新聞 |
セネガルがPK制し初V サッカー、アフリカ選手権 |
https://www.hokkaido-np.co.jp/article/642657/
|
選手権 |
2022-02-07 08:03:00 |
ビジネス |
東洋経済オンライン |
松屋とくら寿司、まったく異なる「出店の思惑」 コロナ禍で激変した業態ごとの拡大戦略 | 外食 | 東洋経済オンライン |
https://toyokeizai.net/articles/-/508513?utm_source=rss&utm_medium=http&utm_campaign=link_back
|
厚木街道 |
2022-02-07 09:00:00 |
コメント
コメントを投稿